Skip to content

Instantly share code, notes, and snippets.

@ato
Created April 5, 2010 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ato/355896 to your computer and use it in GitHub Desktop.
Save ato/355896 to your computer and use it in GitHub Desktop.
(defn rolling-sum
([coll] (rolling-sum coll 0))
([coll init]
(lazy-seq
(when (seq coll)
(let [value (+ (first coll) init)]
(cons value (rolling-sum (next coll) value)))))))
(rolling-sum [3 3 4 3])
;;=> (3 6 10 13)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment