There's a few new functions that have been added with Transducers which mostly have very clear use cases to me. What are the use cases for the new
eduction function? (which looks like it was previously called iteration). The example at
http://clojure.org/transducers is informative. It looks similar to sequence in that it produces something that is seq-able with the major difference being that the transform is applied each time the sequence is traversed.
You can see the difference here in this code (This uses iteration instead of eduction because I was on 1.7.0-alpha2)
(def to-str-iteration
(iteration (map (fn [i]
(println "iteration" i)
(str i)))
(range 3)))
(def to-str-seq
(sequence (map (fn [i]
(println "sequence" i)
(str i)))
(range 3)))
(println "First iteration")
(dorun to-str-iteration)
(println "Second iteration")
(dorun to-str-iteration)
(println "First sequence")
(dorun to-str-seq)
(println "Second sequence")
(dorun to-str-seq)
Printed:
First iteration
iteration 0
iteration 0
iteration 1
iteration 2
Second iteration
iteration 0
iteration 0
iteration 1
iteration 2
First sequence
sequence 0
sequence 1
sequence 2
Second sequence
Should we use eduction when we need side effects or reading the current state during a transform and sequence when the transform is pure? Or is there a subtler difference between the two that I'm missing?