Skip to content

Instantly share code, notes, and snippets.

@hyone
Created May 29, 2011 08:21
Show Gist options
  • Save hyone/997565 to your computer and use it in GitHub Desktop.
Save hyone/997565 to your computer and use it in GitHub Desktop.
Accumulator by Clojure
(defn accumulator [n]
(let [i (atom n)]
(fn [x] (swap! i + x))))
;; user> (doseq [i (range 1 6)] (-> i (* 2) acc println))
;; 2
;; 6
;; 12
;; 20
;; 30
;; nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment