;; *** before: ***
(defn describe-old [n]
(let [m {:n n}
m (if (even? n) (assoc m :parity :even) m)
m (if (pos? n) (update-in m [:n] inc) m)]
m))
(describe-old 4)
;=> {:n 5, :parity :even}
;; *** in version 1.5: ***
;; cond-> threads the value through -> only for the true clauses
(defn describe [n]
(cond-> {:n n}
(even? n) (assoc :parity :even)
(pos? n) (update :n inc)))
(describe 4)
;=> {:n 5, :parity :even}
;; cond->> is the same idea for ->> - the value goes last
(defn totals [coll]
(cond->> coll
true (map inc)
(seq coll) (reduce +)))