Created
May 20, 2015 20:46
-
-
Save anonymous/05428c95465d590400be to your computer and use it in GitHub Desktop.
Rolling up data
This file contains 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
;; Before | |
(def data | |
[ | |
{:id :one :location "A"} | |
{:id :two :location "X"} | |
{:id :one :location "B"} | |
{:id :two :location "Y"} | |
{:id :one :location "C"} | |
{:id :two :location "Z"} | |
] | |
) | |
;; After | |
{ | |
:one {:id :one :location ["A" "B" "C"]} | |
:two {:id :two :location ["X" "Y" "Z"]} | |
} | |
;; I know how to manipulate vector of maps -> map of maps... | |
(#(zipmap (map :id %) %) data) | |
;; ...but this doesn't do the "rolling up" that I'm looking for | |
;; => {:two {:id :two, :location "Z"}, :one {:id :one, :location "C"}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment