Search code examples
clojure

Clojure function to successively add vector elements (numbers)


(def coll [10 27 7 12])

Desired result is:

==> (10 37 44 56)

I tried:

(map #(+ % (next %)) coll)

with no success


Solution

  • reductions can do that:

    (reductions + [10 27 7 12])
    ; → (10 37 44 56)