Created
March 13, 2016 20:57
-
-
Save keyvanakbary/ea73383e873b316e7944 to your computer and use it in GitHub Desktop.
Stateful Accumulator
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 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