Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created February 27, 2013 20:16
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 amalloy/5051301 to your computer and use it in GitHub Desktop.
Save amalloy/5051301 to your computer and use it in GitHub Desktop.
(let [inputs [{:date1
[{:user "user 1"
:metric1 1
:metric2 2}
{:user "user 2"
:metric1 3
:metric2 4}]}
{:date2
[{:user "user 1"
:metric1 5
:metric2 6}
{:user "user 2"
:metric1 7
:metric2 8}]}]]
(reduce (fn [m path]
(assoc-in m (pop path) (peek path)))
{}
(for [input inputs,
[date objs] input
obj objs
:let [user (:user obj), obj (dissoc obj :user)]
[metric value] obj]
[metric date (str "user " user) value])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment