Skip to content

Instantly share code, notes, and snippets.

@vasily-kirichenko
Created November 6, 2012 17:27
Show Gist options
  • Save vasily-kirichenko/4026186 to your computer and use it in GitHub Desktop.
Save vasily-kirichenko/4026186 to your computer and use it in GitHub Desktop.
Thread-it data
(defmacro thread-it [& [first-expr & rest-exprs]]
(if (empty? rest-exprs)
first-expr
`(let [~'it ~first-expr]
(thread-it ~@rest-exprs))))
(def jay {:name "jay fields" :employer "drw.com" :current-city "new york"})
(def john {:name "john dydo" :employer "drw.com" :current-city "new york"})
(def mike {:name "mike ward" :employer "drw.com" :current-city "chicago"})
(def chris {:name "chris george" :employer "thoughtworks.com" :current-city "new york"})
(thread-it
[jay john mike chris]
(filter (comp (partial = "new york") :current-city) it)
(group-by :employer it)
(update-in it ["drw.com"] (partial map :name)))
=>
{"drw.com" ("jay fields" "john dydo"),
"thoughtworks.com"
[{:name "chris george",
:current-city "new york",
:employer "thoughtworks.com"}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment