Generalized Threading Macro in Clojure

clojure, macros

Solution

The 'diamond wand' from Swiss Arrows library would do what you're asking for:

(-<> 0
 (* <> 5)
 (vector 1 2 <> 3 4))
; => [1 2 0 3 4]

That said, it isn't something you end up needing often (or ever in my Clojure experience)

Problem

Note: this is NOT about concurrency. This is about the thread macro. I know that `->` puts the object at the 2nd position and `->>` puts the argument at the last position. Now, I'm curious, much like the short hand notation of `#( ... % )` for functions, is there a short hand notation for threads that lets me place the argument at arbitrary location? The goal would be that instead of having a fixed location for the thread to run through ... I can write arbitrary forms, and insert %% at special places, and the %% is where the thread gets inserted. Thanks!

Original source