Is there something like a consuming take?
berni
someone at somewhere.com
Sun Jul 7 18:36:42 UTC 2019
On Sunday, 7 July 2019 at 09:01:53 UTC, Jonathan M Davis wrote:
> Without slicing, that's impossible without iterating over the
> elements multiple times.
That's what I thought too, but meanwhile I think it is possible.
To get it working, the second range needs to know about the first
one and when the second one is queried the first time it has to
notify the first one, that it has to remove all remaining items
from the underlying range (and in case it still needs them, save
them) and never use it again.
The advantage of this setup over copying the items immediately is
some sort of laziness. It might happen, that the second one will
never query or it might happen, that the first one finished
allready when the second one queries. In this cases no additional
memory is needed.
Even if the second one is queried before the first one finished,
the needed buffer might be much smaller.
More information about the Digitalmars-d-learn
mailing list