Created
April 5, 2010 01:36
-
-
Save ato/355896 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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