Is there something like a consuming take?

berni someone at somewhere.com
Sat Jul 6 11:20:50 UTC 2019


I want to copy the first n items of a range to an array, removing 
these items from the range.

This works:

> foreach (i;0..n)
> {
>    data ~= r.front;
>    r.popFront();
> }

but looks a little bit arkward.

I came up with this now:

> data = r.take(n).array;

This works partly, because the values of r are not consumed. So I 
have to call afterwards:

> r = r.drop(n);

Now I wonder, if it is possible to do this with one single call, 
something like

data = r.take_consuming(n).array;

Does there something like this exist?




More information about the Digitalmars-d-learn mailing list