Skip to content

clojure.core/transduce

View this page on ClojureDocs

Type: function Added: Clojure 1.7 Examples: 7 Runnable: 5
([xform f coll] [xform f init coll])

reduce with a transformation of f (xf). If init is not supplied, (f) will be called to produce it. f should be a reducing step function that accepts both 1 and 2 arguments, if it accepts only 2 you can add the arity-1 with 'completing'. Returns the result of applying (the transformed) xf to init and the first item in coll, then applying xf to that result and the 2nd item, etc. If coll contains no items, returns init and f is not called. Note that certain transforms may inject or skip items.

Examples

by bsvingen on
by upgradingdave on
by jvanderhyde on . May have evaluation errors.
by vspinu on . May have evaluation errors.
by didibus on
by tomdl89 on
by cstml on

Note by jvanderhyde

Usually you use existing functions to create the transformation, using map, filter, paritition-all, etc. But you can also define your own transformations. A transformation (or transducer) is a function that takes a reducing function and returns a reducing function. See the source for take and filter for examples.

See also


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