Skip to content

Instantly share code, notes, and snippets.

@halgari
Created December 3, 2012 14:35
Show Gist options
  • Save halgari/4195378 to your computer and use it in GitHub Desktop.
Save halgari/4195378 to your computer and use it in GitHub Desktop.
Atom refactoring
(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