Fork me on GitHub
#portland-or
<
2015-12-07
>
bill19:12:55

Cursive Clojure tip-o’-th’-mornin’: Refactor Threading/Unthreading. Put this in your source file or REPL:

(conj (conj (conj [] 1) 2) 3)
                    ^
and position your mouse at that ^ there (before the 1) and hit ⌘⌥, (that’s command-option-comma) and notice that the expression is changed to use the “thread last macro”. Hit ⌘⌥, again and notice that the next enclosing expression is changed to use the “thread first macro”.
(conj (-> (->> 1 (conj [])) (conj 2)) 3)
     ^
Reverse the process with ⌘⌥. (that’s command-shift-period). Experiment with some different forms. Notice that sometimes you are prompted for the macro form to use (thread first versus last). This is not only useful for folks who understand ->> and ->, it can also help us understand those important macros.