Skip to content

Instantly share code, notes, and snippets.

@keyvanakbary
Created March 13, 2016 20:57
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 keyvanakbary/ea73383e873b316e7944 to your computer and use it in GitHub Desktop.
Save keyvanakbary/ea73383e873b316e7944 to your computer and use it in GitHub Desktop.
Stateful Accumulator
(defn make-acumulator [value]
(def acc (atom value))
(fn [add]
(swap! acc #(+ % add))
@acc))
(def a (make-acumulator 10))
(a 10)
;20
(a 10)
;30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment