Hello,

eduction does not return a seq, or anything already "concrete" like that,
rather it returns a new reducible, with the interesting property lying in
the retention of the xform argument (a transducer).

This allows you, for instance, to pass around a collection with all the
processing steps but the final rendering of the result (a seq? an aggregate
result? a vector ? nil?) => it's up to the user of the educible.

Since the educible is an unreduced form of the initial collection, then
every time it will be "realized" into a concrete value, the hidden (behind
the xform) collection will be traversed, and the transducer-returned
reducing function called.

Le mercredi 8 octobre 2014, Jason Gilman <jason.gil...@gmail.com> a écrit :

> 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
> <http://clojure.github.io/clojure/branch-master/clojure.core-api.html#clojure.core/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?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> <javascript:_e(%7B%7D,'cvml','clojure@googlegroups.com');>
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> <javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com');>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com
> <javascript:_e(%7B%7D,'cvml','clojure%2bunsubscr...@googlegroups.com');>.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Laurent Petit

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to