Generalized Threading Macro in Clojure

There is now a generalized threading macro in Clojure since 1.5 called as->.

This tweet gives an example of how it works: https://twitter.com/borkdude/status/302881431649128448

(as-> "/tmp" x
      (java.io.File. x)
      (file-seq x)
      (filter (memfn isDirectory) x)
      (count x))

First ‘x’ is bound to “/tmp” and a file is made out of it. ‘x’ is rebound again to the resulting file and a put through the ‘file-seq’ function, etc.

Leave a Comment