(cond->> expr & clauses)
Takes an expression and a set of test/form pairs. Threads expr (via ->>) through each form for which the corresponding test expression is true. Note that, unlike cond branching, cond->> threading does not short circuit after the first true test expression.
;; useful for when you want to control doing a bunch of things to a lazy sequence
;; based on some conditions or, commonly, keyword arguments to a function.
(defn do-stuff
[coll {:keys [map-fn max-num-things batch-size]}]
(cond->> coll
map-fn (map map-fn)
max-num-things (take max-num-things)
batch-size (partition batch-size)))
user=> (do-stuff [1 2 3 4] {})
[1 2 3 4]
user=> (do-stuff [1 2 3 4] {:map-fn str})
("1" "2" "3" "4")
user=> (do-stuff [1 2 3 4] {:map-fn str :batch-size 2})
(("1" "2") ("3" "4"))
user=> (do-stuff [1 2 3 4] {:map-fn str :max-num-things 3})
("1" "2" "3")