Skip to content

Instantly share code, notes, and snippets.

@clifford
Forked from gerritjvv/merge-stats-map.clj
Created May 28, 2014 17:59
Show Gist options
  • Save clifford/0864cdfdfc5f639b5628 to your computer and use it in GitHub Desktop.
Save clifford/0864cdfdfc5f639b5628 to your computer and use it in GitHub Desktop.
(def msgs [ {"a" {:stat1 1 :stat2 10} "b" {:stat1 1}} {"a" {:stat1 1}}])
(def merged (apply merge-with (partial merge-with +) msgs))
;; {"a" {:stat1 2, :stat2 10}, "b" {:stat1 1}}
(prn merged)
;; {"a" {:stat1 2, :stat2 10}, "b" {:stat1 1}}
(= (-> merged first second :stat1) 2)
;; true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment