Last active
August 29, 2015 14:01
-
-
Save gerritjvv/9bd082b905d56aef3526 to your computer and use it in GitHub Desktop.
The map is formed of key = topic, value = stats map of numeric stats The task was to aggregate the numeric values in the stats map for similar topics, each message could have multiple topics.
This file contains hidden or 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
(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