digitalmars.D.bugs - [Issue 13029] New: cumulate for std.algorithm
- via Digitalmars-d-bugs (30/30) Jul 03 2014 https://issues.dlang.org/show_bug.cgi?id=13029
https://issues.dlang.org/show_bug.cgi?id=13029 Issue ID: 13029 Summary: cumulate for std.algorithm Product: D Version: D2 Hardware: x86_64 OS: All Status: NEW Severity: enhancement Priority: P1 Component: Phobos Assignee: nobody puremagic.com Reporter: jens.k.mueller gmx.de 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. --
Jul 03 2014