macro | since v0.0-1798 | imported clojure.core/as-> | Edit |
(as-> expr name & forms)
Binds name
to expr
, evaluates the first form in the lexical context of that
binding, then binds name
to that result, repeating for each successive form,
returning the result of the last form.
Useful for when you want a threading macro to use different "places" at each form.
(as-> [1 2 3 4] x
(reduce + x)
(/ x 2))
;;=> 5
Binds name to expr, evaluates the first form in the lexical context of that binding, then binds name to that result, repeating for each successive form, returning the result of the last form.
(defmacro as->
{:added "1.5"}
[expr name & forms]
`(let [~name ~expr
~@(interleave (repeat name) (butlast forms))]
~(if (empty? forms)
name
(last forms))))