I'm surprised no one has mentioned that as->
is designed to work inside ->
(all the threading macros work inside ->
). Going through other people's answers, here's what I'd expect:
(-> 2
(+ 1)
(as-> x (* 2 x)) ; or just (->> (* 2))
(range))
(-> thing
(->> (fn2 bleh)) ; or (as-> x (fn2 bleh x))
(fn3 blah))
As you can see, the argument order of as->
-- expr symbol body -- lends itself to threading, but in both these cases you could simply thread from ->
into ->>
to have the threaded value at the end of the form.
as->
shines when you have just one or two forms in an otherwise straight-line thread that do not want the threaded value at the beginning or at the end:
(-> thing
(fn1 arg2 arg3)
(+ 13)
(as-> q (fn2 arg1 q arg3))
(fn3 second-arg))
Or, perhaps, you need a let
for destructuring or something:
(-> foo
(processs-it :expand)
(as-> m (let [{:keys [start end]} m]
(- end start)))
(categorize-interval))