[Issue 11084] New: std.algorithm.scan
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Sep 21 05:47:17 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11084
Summary: std.algorithm.scan
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2013-09-21 05:47:16 PDT ---
I suggest to add to Phobos a function that returns a range, with usage very
similar to std.algorithm.reduce, that returns all the intermediate values.
An example from Haskell:
Prelude> [1 .. 10]
[1,2,3,4,5,6,7,8,9,10]
Prelude> scanl (+) 0 [1 .. 10]
[0,1,3,6,10,15,21,28,36,45,55]
Prelude> scanr (+) 0 [1 .. 10]
[55,54,52,49,45,40,34,27,19,10,0]
That is also related to the FoldList of Mathematica:
http://reference.wolfram.com/mathematica/ref/FoldList.html
In D it could work like this:
iota(1, 11).scan!q{a + b}(0).writeln
==>
[0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55]
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list