Created
December 3, 2012 14:35
-
-
Save halgari/4195378 to your computer and use it in GitHub Desktop.
Atom refactoring
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 update-my-atom [a name] | |
(let [new-state (assoc-in @a [:foo :bar] merge {:name name})] | |
(swap! a (fn [old] new-state)))) | |
;; refactored into: | |
(defn get-new-state [state name] | |
(assoc-in state [:foo :bar] merge {:name name})) | |
(defn update-my-atom [a name] | |
(swap! a get-new-state name)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment