Comment #0 by jens.k.mueller — 2014-07-03T08:51:17Z
cumulate is an algorithm that I use rarely but still I believe it belongs into the standard library.
cumulate applies a binary function to a range in a cumulative manner. Matlab has cumsum and cumprod (see http://www.mathworks.de/de/help/matlab/ref/cumsum.html and http://www.mathworks.de/de/help/matlab/ref/cumprod.html).
Some unittests to define its behavior.
unittest
{
assert([].cumulate!((a,b) => a + b).equal([]));
assert([1].cumulate!((a,b) => a + b).equal([1]));
assert([1,2,3].cumulate!((a,b) => a + b).equal([1,3,6]));
}
It may very well be the case that one can express this functionality using other functions from std.algorithm. If there is an easy approach, I may follow that way. I couldn't fine one.
Comment #1 by bearophile_hugs — 2014-07-03T09:04:52Z
(In reply to jens.k.mueller from comment #0)
> assert([1,2,3].cumulate!((a,b) => a + b).equal([1,3,6]));
Dupe (with a different name) of Issue 12655 ?
Comment #2 by jens.k.mueller — 2014-07-03T09:11:12Z
*** This issue has been marked as a duplicate of issue 12655 ***