You can do this with cond-> recently introduced in Clojure 1.5:
(cond-> x true a (> (ax) 2) b true c)
Or better
(-> x a (cond-> (> (ax) 2) b) c)
Meaning: "take x , pass it through a , take the result and pass it through b if (> (ax) 2) or leave it unchanged, finally take what you have and pass it through c ."
In other words, cond-> is similar to -> , except that instead of separate forms for streaming your expression through it, pairs of test + forms are taken, where the form is skipped if the test is false and used for streaming if the test is plausible
(cond-> x test-1 form-1 test-2 form-2) ;; if test-1 is truthy and test-2 is falsey, output is as if from (-> x test-1) ;; if it the other way around, output is as if from (-> x test-2) ;; if both tests are truthy: (-> x test-1 test-2) ;; if both tests are falsey: x
source share