On Friday, 16 October 2015 at 11:38:35 UTC, John Colvin wrote:
import std.range, std.algorithm;auto slidingWindow(R)(R r, size_t n) if(isForwardRange!R) { //you could definitely do this with less overhead return roundRobin(r.chunks(n), r.save.drop(1).chunks(n)) .filter!(p => p.length == n); } auto adjacentDiff(R)(R r) { return r.slidingWindow(2).map!"a[1] - a[0]"; }
Nice !I wanted to use lockstep(r, r.dropOne) but it doesn't return a Range :-/
It has to be used in a foreach.