Idiomatic adjacent_difference

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 16 06:44:02 PDT 2015


On Friday, 16 October 2015 at 12:03:56 UTC, Per Nordlöw wrote:
> On Friday, 16 October 2015 at 11:48:19 UTC, Edwin van Leeuwen 
> wrote:
>> zip(r, r[1..$]).map!((t) => t[1]-t[0]);
>
> And for InputRanges (not requiring random-access):
>
> zip(r, r.dropOne).map!((t) => t[1]-t[0]);

We should have a good implementation of slidingWindow in 
std.range, it's a useful iteration pattern (although it does 
sometimes encourage inefficient algorithms).


More information about the Digitalmars-d-learn mailing list