I've found that adding side effects to a Clojure transducer can result in the following unexpected behavior:
(def counter (atom 0))
(def increment-counter-xform
(map (fn [sample]
(swap! counter inc)
sample)))
(eduction increment-counter-xform (range 100))
@counter ;; => 100, as expected
(reset! counter 0)
(eduction increment-counter-xform (range 1000))
@counter ;; => 129, but I expected 1000
Why does the above code block increment the counter the expected number of times for small numbers of samples, but not for large numbers of samples? It appears that even if the argument to range is very large, the counter will never be incremented more than 129 times.