Consume an entire range

Jonathan M Davis jmdavisProg at gmx.com
Wed May 29 21:00:19 PDT 2013


On Thursday, May 30, 2013 05:53:02 Brad Anderson wrote:
> On Thursday, 30 May 2013 at 03:50:52 UTC, Brad Anderson wrote:
> > Is there a simple way to consume a range apart from
> > std.array.array?  I don't need to result of the range stored in
> > an array, I just need a lazy map to evaluate completely.
> 
> Obviously I could just popFront.  To be more clear, I want
> something like eat() or consume() or exhaust() that I can tack on
> the end of my chained algorithm calls.

If you specifically want to iterate over it, then I think that you need to 
repeatedly call popFront (or callPopFrontN if it hasLength). However, if what 
you want is for the resultant range to be empty, you can use 
std.range.takeNone. If it can, it'll return the same range type as the 
original, and if it can't, it'll return takeExactly(range, 0).

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list