code-reviews

2018-04-27T20:10:17.000332Z

I just figured out something interesting and wanted to share it. Suppose you have a threading macro variant that accepts multiple inputs. Let’s suppose you have when-> in your toolbox.:

(-> 123 
    (when-> number? inc)
    str)
; => "124"

(-> :x
    (when-> number? inc)
    str)
; => ":x"
Now suppose you want to rewire the inputs and output of when-> to specific arbitrary values. How would you write this ?
(-> 123
    (when-> (<- *option*)
      inc)
    str)

(-> 123
    (when-> number? (<- "number"))
    (when-> keyword? name)
    ...)
Here is how I wrote <-:
(defmacro <- [& body]
  `((fn [& _#] ~@body)))

slipset 2018-04-27T20:16:37.000438Z

Looks a lot like cond->>

2018-04-27T20:19:41.000090Z

cond-> doesn’t handle threading the value to test forms

seancorfield 2018-04-27T20:25:16.000568Z

We have condp-> and condp->> macros at work that thread through both the predicate and the expression. I suspect it's a fairly common pattern.

2018-04-27T20:37:35.000588Z

I wrote a macro to define -> and ->> variants in one shot. With a few examples: