Created
June 17, 2015 12:57
-
-
Save oliyh/bf98c3774b07cdf2572f to your computer and use it in GitHub Desktop.
Combining Clojure macros some-> and as->
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
(defmacro someas-> | |
"A mixture of some-> and as-> allowing more flexibility in the step forms" | |
[expr name & forms] | |
(let [pstep (fn [step] `(if (nil? ~name) nil ~step))] | |
`(let [~name ~expr | |
~@(interleave (repeat name) (map pstep forms))] | |
~name))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment