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;

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?

Reply via email to