Skip to content

Instantly share code, notes, and snippets.

@dyba
Forked from halgari/gist:4195378
Created December 3, 2012 20:42
Show Gist options
  • Save dyba/4197857 to your computer and use it in GitHub Desktop.
Save dyba/4197857 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