A function for iterables like Clojure's reductions

I’ve searched, believe me, but every language calls it something different. In Clojure, it’s reductions, in APL it’s . It works like reduce, but where reduce reduces to one value, it returns all the intermediate values leading to the last which would be the return from reduce: thus (in APL) +\1 2 3 4 5 would result in 1 3 6 10 15.

Obviously, it isn’t hard to write a loop for it, which is what I’m doing now, but I figured maybe it is hiding in plain site in the API.

1 Like

I do believe you do want:

julia> accumulate((+), [1, 2, 3, 4, 5])
5-element Array{Int64,1}:
  1
  3
  6
 10
 15

2 Likes

Perfect! Thanks!