October 06, 2016 Re: Rust-like collect in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On 10/06/2016 04:32 PM, Nordlöw wrote: > Is there a concept in D similar to Rust's `collect`: > > https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect > > If not, I'm eager to implement it to support D-style containers. > > What would the desired interface look like? > > Perhaps: > > 0.iota(n).collect!Array > > Or can/should we just overload `std.conv.to` as > > 0.iota(n).to!Array > > eventhough the element type is not explicit in the expression `to.!Array`? https://dlang.org/phobos/std_container_util.html#.make ---- import std.container.array: Array; import std.container.util: make; import std.range: iota; void main() { auto arr = 0.iota(99).make!Array; } ---- |
October 06, 2016 Re: Rust-like collect in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to ag0aep6g | On 10/06/2016 07:44 PM, ag0aep6g wrote: > https://dlang.org/phobos/std_container_util.html#.make More specifically, the second overload is where it's at: https://dlang.org/phobos/std_container_util.html#.make.2 |
October 12, 2016 Re: Rust-like collect in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On 10/06/2016 10:32 AM, Nordlöw wrote:
> Is there a concept in D similar to Rust's `collect`:
>
> https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect
That's "make" in std.container. Is that what you're looking for? As an aside, "collect" is an awful abbreviation of "collection". -- Andrei
|
October 13, 2016 Re: Rust-like collect in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Thursday, 13 October 2016 at 01:15:22 UTC, Andrei Alexandrescu wrote:
> On 10/06/2016 10:32 AM, Nordlöw wrote:
>> Is there a concept in D similar to Rust's `collect`:
>>
>> https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect
>
> That's "make" in std.container. Is that what you're looking for? As an aside, "collect" is an awful abbreviation of "collection". -- Andrei
I've always thought of it more as "collect the elements of the iterator into a container".
|
October 13, 2016 Re: Rust-like collect in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta Attachments:
| On Thu, 2016-10-13 at 02:33 +0000, Meta via Digitalmars-d-learn wrote: > On Thursday, 13 October 2016 at 01:15:22 UTC, Andrei Alexandrescu wrote: > > On 10/06/2016 10:32 AM, Nordlöw wrote: > > > Is there a concept in D similar to Rust's `collect`: > > > > > > https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.col lect > > > > That's "make" in std.container. Is that what you're looking for? As an aside, "collect" is an awful abbreviation of "collection". -- Andrei > > I've always thought of it more as "collect the elements of the iterator into a container". Java and Rust have gone the same route. collect is a terminal operation creating a data structure given a potentially infinite, lazily evaluated, stream. Rust uses iter for creating a stream from a data structure, Java uses stream or parallelstream. Java's parallelstream seems to be missing from Rust, but there is Rayon to provide a version. D's std.parallelism does something of this, but it needs more work to provide the tree-structured as well as scatter–gather internal parallelism models. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder |
October 13, 2016 Re: Rust-like collect in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu Attachments:
| On Wed, 2016-10-12 at 21:15 -0400, Andrei Alexandrescu via Digitalmars- d-learn wrote: > On 10/06/2016 10:32 AM, Nordlöw wrote: > > Is there a concept in D similar to Rust's `collect`: > > > > https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.colle ct > > That's "make" in std.container. Is that what you're looking for? As > an > aside, "collect" is an awful abbreviation of "collection". -- Andrei I's say collect has an interesting history. Smalltalk used collect for what other called map. Various languages, including Groovy, continued this tradition. Now Rust and Java are using collect as a verb-like form, just as D uses make. collection would be wrong here. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder |
October 13, 2016 Re: Rust-like collect in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | On Thursday, 13 October 2016 at 05:07:26 UTC, Russel Winder wrote:
> Java and Rust have gone the same route. collect is a terminal operation creating a data structure given a potentially infinite, lazily evaluated, stream.
Is D somehow better here?
For instance, we can use `if (!isInfinite!Range)` to forbid collecting values from an infinite `Range`. Is this checking done? That is
`0.iota.make!Array`
should not be allowed.
|
October 13, 2016 Re: Rust-like collect in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Thursday, 13 October 2016 at 10:00:56 UTC, Nordlöw wrote: > For instance, we can use `if (!isInfinite!Range)` to forbid collecting values from an infinite `Range`. Is this checking done? That is > > `0.iota.make!Array` > > should not be allowed. https://github.com/dlang/phobos/pull/4860 |
Copyright © 1999-2021 by the D Language Foundation