www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - skip(N) range

reply Adam Wey <adamwey thisisnotmyemail.com> writes:
Is there a skip() function for ranges? I need to skip N elements of a range
and then take M elements. Something like

writeln(take(range, 10), ": ", take(skip(range, 10), 10));

Thanks
Jul 19 2011
next sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On 2011-07-19 17:29, Adam Wey wrote:
 Is there a skip() function for ranges? I need to skip N elements of a range
 and then take M elements. Something like
 
 writeln(take(range, 10), ": ", take(skip(range, 10), 10));

No, but this pull request https://github.com/D-Programming-Language/phobos/pull/147 will introduce the drop function which does that. It hasn't been merged in yet though. The closest that there is right now is to call popFrontN, but you can't do that in the middle of an expression like that. - Jonathan M Davis
Jul 19 2011
prev sibling parent Jesse Phillips <jessekphillips+D gmail.com> writes:
Adam Wey Wrote:

 Is there a skip() function for ranges? I need to skip N elements of a range
 and then take M elements. Something like
 
 writeln(take(range, 10), ": ", take(skip(range, 10), 10));
 
 Thanks

There is popFrontN http://d-programming-language.org/phobos/std_range.html#popFrontN
Jul 19 2011