Rust-like collect in D
Dicebot via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Oct 6 09:14:33 PDT 2016
On Thursday, 6 October 2016 at 14:32:44 UTC, 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`?
If an entity (i.e. container) implements OutputRange API, you can
already do it:
0.iota(n).copy(container);
More information about the Digitalmars-d-learn
mailing list