(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.
(def owners [{:owner "Jimmy"
:pets (ref [{:name "Rex"
:type :dog}
{:name "Sniffles"
:type :hamster}])}
{:owner "Jacky"
:pets (ref [{:name "Spot"
:type :mink}
{:name "Puff"
:type :magic-dragon}])}])
;; This example is contrived as there are other more
;; terse ways of expressing the idea. It demonstrates
;; several of the ways to extract items from a collection.
;; Notice how the collection can be used in function or
;; parameter position.
(as-> owners $ (nth $ 0) (:pets $) (deref $) ($ 1) ($ :type))
;;=> :hamster
(as-> 0 n
(inc n) ; n is 0 here passed from first parameter to as->
(inc n)) ; n is 1 here passed from result of previous inc expression
;;=> 2
; use it in the middle of a -> pipeline to sprinkle in some flexibility
(-> [10 11]
(conj 12)
(as-> xs (map - xs [3 2 1]))
(reverse))
; (11 9 7)
;; when you want to use arbitrary positioning of your argument in a thread macro
(as-> {:a 1 :b 2} m
(update m :a + 10)
(reduce (fn [s [_ v]] (+ s v)) 0 m))
;; when you'd like an if statement in your thread
(as-> {:a 1 :b 2} m
(update m :a + 10)
(if update-b
(update m :b + 10)
m))