# A function for iterables like Clojure's reductions

**URL:** <https://discourse.julialang.org/t/a-function-for-iterables-like-clojures-reductions/78407>\
**Category:** General Usage\
**Created:** [March 24, 2022, 3:36pm UTC](https://discourse.julialang.org/t/a-function-for-iterables-like-clojures-reductions/78407 "2022-03-24T15:36:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bwanab](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bwanab/32/35903_2.png) [@bwanab](https://discourse.julialang.org/u/bwanab)\
**Post date:** [March 24, 2022, 3:36pm UTC](https://discourse.julialang.org/t/a-function-for-iterables-like-clojures-reductions/78407/1 "2022-03-24T15:36:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 24, 2022, 3:43pm UTC](https://discourse.julialang.org/t/a-function-for-iterables-like-clojures-reductions/78407/2 "2022-03-24T15:43:00Z")

</div>

I do believe you do want:

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

```

---

<div class="post-metadata">

**Author:** ![bwanab](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bwanab/32/35903_2.png) [@bwanab](https://discourse.julialang.org/u/bwanab)\
**Post date:** [March 24, 2022, 4:23pm UTC](https://discourse.julialang.org/t/a-function-for-iterables-like-clojures-reductions/78407/3 "2022-03-24T16:23:12Z")

</div>

Perfect! Thanks!
