r/foldcat combines the chunk results of a fold into a reducible, foldable concatenation tree. It coordinates r/cat as the combiner with r/append! as the reducing function, avoiding repeated construction of temporary persistent data structures. section 7.1.4
Its contract and resulting structure are:
- Accepts a collection satisfying the fold contract and returns a network of counted Cat objects. section 7.1.4
- Supports constant-time counting, reduction, and further folding because Cat nodes are counted and reducible. section 7.1.4
- Uses mutable collection accumulators during chunk reduction, then combines them into a concatenation tree. section 7.1.4
- Can replace r/fold r/cat r/append! when the default ArrayList accumulator is appropriate; r/cat accepts a zero-argument constructor for alternatives. section 7.1.4
Fold transformed data into a concatenation
With a reducer pipeline over 1,000 values, (take 5 (r/foldcat input)) yields (1 2 3 4 5). A word-processing pipeline can likewise produce a large lazy-looking result whose first entries are ["the" 3], ["project" 7], and ["gutenberg" 9]. Inspecting that result shows a clojure.core.reducers.Cat with constant-time count and left/right child nodes.
Choose a different accumulator
Pass #(HashSet.) to r/cat when chunk results should accumulate into sets, or #(StringBuilder.) with an append function when building text. The resulting Cat tree can be traversed or reduced for later operations such as distinct-word extraction and letter-frequency analysis.
