Add accumulate/scan to the standard library

(^) #1

scan or accumulate is the operation that takes an array, and returns an array where each element is the sum (or some other operation) of that element, and all the previous elements. It could be spelled similar to reduce right now.

[1, 2, 3, 4, 5].scan(+) -> [1, 3, 6, 10, 15]

i find myself reaching for this a lot, and am always surprised it’s not in the standard library. a lot of other people reach for it too. does this clear the bar for inclusion in the standard library?

(Steve Canon) #2

I have always called this operation a “prefix sum” (or more generally a prefix reduce), FWIW.

(Matthew Johnson) #3

scan was already reviewed and rejected: Do you think you can provide sufficient motivation to overcome the rationale for rejection?