Clojure 函数连续添加向量元素(数字)
Clojure function to successively add vector elements (numbers)
(def coll [10 27 7 12])
想要的结果是:
==> (10 37 44 56)
我试过了:
(map #(+ % (next %)) coll)
没有成功
reductions
可以做到:
(reductions + [10 27 7 12])
; → (10 37 44 56)
(def coll [10 27 7 12])
想要的结果是:
==> (10 37 44 56)
我试过了:
(map #(+ % (next %)) coll)
没有成功
reductions
可以做到:
(reductions + [10 27 7 12])
; → (10 37 44 56)