lookahead on ranges

Sebastian Graf SebastianGraf at t-online.de
Mon Apr 29 10:02:22 PDT 2013


On Monday, 29 April 2013 at 16:39:21 UTC, bearophile wrote:
>
> I think there isn't something like that in Phobos (I can't be 
> fully sure because std.algorithm and std.range contain lot of 
> powerful stuff, and it's not easy to know every possible 
> combination of them).
>
> So I think you should use zip.
>
> Time ago I have suggested to add a second argument to chunks:
> http://d.puremagic.com/issues/show_bug.cgi?id=6621
>
> With that you can do something like:
>
> auto arr = [1,2,3,4,5];
> auto delta = arr.chunks(2, 1).map!(p => p[1] - p[0]);
>
>
> Note that today this:
>
> assert(equal(delta[], [1,1,1,1][]));
>
> is written like this:
>
> assert(equal(delta, [1,1,1,1]));
>
> Or even:
>
> assert(delta.equal([1,1,1,1]));
>
> The online documentation is old.
>
> Bye,
> bearophile

Thanks. Sounds good.


More information about the Digitalmars-d-learn mailing list