as->

macrosince v0.0-1798imported clojure.core/as->Edit
(as-> expr name & forms)

Details:

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.


Examples:

(as-> [1 2 3 4] x
  (reduce + x)
  (/ x 2))
;;=> 5

See Also:


Source docstring:
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.
Source code @ clojure:src/clj/clojure/core.clj
(defmacro as->
  {:added "1.5"}
  [expr name & forms]
  `(let [~name ~expr
         ~@(interleave (repeat name) (butlast forms))]
     ~(if (empty? forms)
        name
        (last forms))))