-
-
Save astoddard/3799887 to your computer and use it in GitHub Desktop.
less dry, easier to digest
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
(-> [jay john mike chris] | |
(->> (filter (comp (partial = "new york") :current-city))) | |
(->> (group-by :employer)) | |
(update-in ["drw.com"] (partial map :name))) |
Nifty! I've bumped into the same issue before, and came up with a small, not that clever but occasionally useful macro:
(defmacro thr
"Like the threading macros, but lets you provide a symbol to which the result
of each successive form will be bound before calling the next. Example:
(thr x value
(fn1 :a :b x :c)
(fn2 x :x :y x)
(for [v x] (fn3 v)))"
([sym x form]
`(let [~sym ~x]
~form))
([sym x form & more]
`(thr ~sym (thr ~sym ~x ~form) ~@more)))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While I was writing the entry I was thinking about clojure.set as well, but I didn't want to mix the two ideas. Thanks for the comment and bringing it all together. If we could easily use other keys, here's an example that gets us our desired output.