Skip to content

Instantly share code, notes, and snippets.

@l1x
Last active August 29, 2015 14:00
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 l1x/1d29bc762a316461a849 to your computer and use it in GitHub Desktop.
Save l1x/1d29bc762a316461a849 to your computer and use it in GitHub Desktop.
(def alerts (atom {}))
(defn update-vals [mmap vals f]
(reduce #(update-in % [%2] f) mmap vals))
(swap! alerts update-vals [:a :b :c] (fnil inc 0))
;d-std-alerts.core=> (swap! alerts update-vals [:a :b :c] inc)
;NullPointerException [trace missing]
;dd-std-alerts.core=> (swap! alerts update-in [:a] (fnil inc 0))
;{:a 1}
;dd-std-alerts.core=> (swap! alerts update-in [:b] (fnil inc 0))
;{:b 1, :a 1}
;dd-std-alerts.core=> (swap! alerts update-in [:c] (fnil inc 0))
;{:c 1, :b 1, :a 1}
;dd-std-alerts.core=> (swap! alerts update-vals [:a :b :c] inc)
;{:c 2, :b 2, :a 2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment