A stateful transducer retains partial processing state until reduction finishes. This matters when a transformation buffers or accumulates data, because receiving the final item does not necessarily flush that state. transduce signals completion by calling the reducing function with one argument, allowing the transducer chain to release buffered results consistently. section 7.2.3
Completion flushes partition-all
With (partition-all 3), two inputs remain buffered until the final reducing-function call: (xform-reductor 0 0) ; 0 (xform-reductor 0 0) ; 0 (xform-reductor 0) ; #done! 2 Without that final one-argument call, the buffered values would not be emitted and the result would remain 0. section 7.2.3
(def xform ; #1
(comp (map inc)
(partition-all 3)
cat))
(def xform-reductor ; #2
(xform
(completing +
#(do (print "#done! ") %))))
(xform-reductor 0 0) ; #3
;; 0
(xform-reductor 0 0) ; #4
;; 0
(xform-reductor 0) ; #5
;; #done! 2
Inspect the reducing function and its final one-argument completion call. section 7.2.3
