clojure.core/eduction¶
Returns a reducible/iterable application of the transducers to the items in coll. Transducers are applied in order as if combined with comp. Note that these applications will be performed every time reduce/iterator is called.
Examples¶
Note by glts¶
eduction is particularly useful as an adapter for collection-processing functions that don’t have a transducers arity. For example, you might want to transform a collection before passing it to frequencies. eduction makes that possible and efficient:
(->> coll
(eduction (map #(quot % 5))
(filter odd?))
frequencies)
So eduction turns out to be quite powerful in that it brings the benefits of transducers to all collection-processing functions, even those that predate transducers: first, last, group-by, run!, str/join, …
Note by glts¶
Interesting background about sequence versus eduction: https://groups.google.com/d/msg/clojure/9I6MtgOTD0w/NiG5PimBCP8J
Note by Hindol¶
eduction does not cache the result while sequence does. eduction is intended to be used when you are eventually going to reduce over the sequence.
https://groups.google.com/d/msg/clojure/9I6MtgOTD0w/NiG5PimBCP8J
See also¶
- clojure.core/transduce (5)
- clojure.core/reduce (22)
- clojure.core/reductions (2)
- clojure.core/sequence (1)
Content from the matching ClojureDocs page, with authors credited on each contribution.