Transducers

Clojure 1.7 introduced a new abstraction called transducers for "composable algorithmic transformations", commonly used to apply a series of transformations over collections. The idea of transducers follows from the reducing function, which accepts arguments of the form (result, input) and returns result. A reducing function is what we typically use with reduce. A transducer accepts a reducing function, wraps/composes over its functionality to provide something extra, and returns another reducing function.

The functions in clojure.core that deal with collections have acquired an arity-1 variant, which returns a transducer, namely map, cat, mapcat, filter, remove, take, take-while, take-nth, drop, drop-while, replace, partition-by

Get Clojure High Performance Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.