www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13016] New: std.algorithm.scanl

https://issues.dlang.org/show_bug.cgi?id=13016

          Issue ID: 13016
           Summary: std.algorithm.scanl
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: dev.jahn.marko gmail.com

Add a function scanl (like haskell's scanl) to std.algorithm, that acts like
reduce but returns the intermediate results in a range.

void main() {
import std.stdio, std.algorithm;


writeln(scanl!((x,y)=>x+y)([1,2,3,4,5])); // prints [3,6,10,15]  

uint[] durations = [10,10,15,20,10];
uint[] timeSteps = scanl!( (x,y) => x+y ) (0,durations);

writeln(timeSteps); // prints [10,20,35,55,65]

}

 Maybe suggest another name.

--
Jul 01 2014