Skip to content

Instantly share code, notes, and snippets.

Created May 20, 2015 20:46
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 anonymous/05428c95465d590400be to your computer and use it in GitHub Desktop.
Save anonymous/05428c95465d590400be to your computer and use it in GitHub Desktop.
Rolling up data
;; 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