r/cat combines counted values into a reducible, foldable Cat tree, avoiding repeated construction of temporary persistent collections during parallel folds. It differs from clojure.core/cat, the transducer. With no arguments it returns an empty java.util.ArrayList; with a zero-argument ctor it creates the chosen empty collection; with left and right values it creates a combined node. Inputs may be any counted values, including nil. section 7.1.4
Use the arities according to the fold role:
- Pass r/cat as fold’s combinef alongside r/append! to accumulate mutable leaves into a Cat tree. section 7.1.4
- Use r/foldcat for the standard orchestration; its result remains countable, reducible, and foldable. section 7.1.4
- Supply a ctor such as #(HashSet.) or #(StringBuilder.) when the accumulated collection needs a different mutable type. section 7.1.4
Fold transformed values
(take 5 (r/foldcat (r/map inc (into [] (range 1000))))) ;; (1 2 3 4 5) (def words (r/foldcat (r-word text))) (type words) ;; clojure.core.reducers.Cat
