windowedReduce

Generalized Windowed Reduce. * * See_Also: https://stackoverflow.com/questions/21004944/forward-difference-algorithm * See_Also: http://forum.dlang.org/thread/ujouqtqeehkegmtaxebg@forum.dlang.org#post-lczzsypupcfigttghkwx:40forum.dlang.org * See_Also: http://rosettacode.org/wiki/Forward_difference#D

ref
windowedReduce
()
if (
isInputRange!R
)

Examples

import std.datetime : Clock, SysTime;
SysTime[] times;
immutable n = 4;
foreach (_; 0 .. n)
    times ~= Clock.currTime;
version(show) dbg(times);
auto spans = times.windowedReduce!(Reduction.forwardDifference);
version(show) dbg(spans);
// dbg(*(cast(ulong*)&(spans.front)));
version(show) import std.datetime : Duration;
version(show) dbg(Duration.sizeof);
immutable i = [1, 4, 9, 17];
assert(i.windowedReduce!(Reduction.forwardDifference).equal ([+3, +5, +8]));
assert(i.windowedReduce!(Reduction.backwardDifference).equal([-3, -5, -8]));
assert(i.windowedReduce!(Reduction.sum).equal ([+5, +13, +26]));
assert([1].windowedReduce.empty);
version(show) dbg(i.windowedReduce!(Reduction.sum));

Meta