Skip to content

Latest commit

 

History

History
15 lines (11 loc) · 426 Bytes

reduced.md

File metadata and controls

15 lines (11 loc) · 426 Bytes

reduced

(reduced x)

Wraps x so a reduction stops and answers it: reduce, reduce-kv, transduce, into and the stepping consumers unwrap it, and @ reads it back. As a value a one-argument function.

Deviation: a reduced value prints as its wrapper list, where the oracle prints an object.

(println (reduce (fn [a x] (if (> x 2) (reduced a) (+ a x))) 0 [1 2 3 4])) ; 3
(println @(reduced 5)) ; 5