Skip to content

clojure.core/eduction

View this page on ClojureDocs

Type: function Added: Clojure 1.7 Examples: 6 Runnable: 0
([xform* coll])

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

by ghiden on . May have evaluation errors.
by freckletonj on . May have evaluation errors.
by jvanderhyde on . May have evaluation errors.
by vspinu on . May have evaluation errors.
by onionpancakes on . May have evaluation errors.
by onionpancakes on . May have evaluation errors.

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


Content from the matching ClojureDocs page, with authors credited on each contribution.