Parallelism with Reducers

Most data manipulation in Clojure is specified in terms of functions applied over sequences. Sequences (by their definition) are logical lists of values in some order. Most of the core library sequence functions are applied lazily, in order, and on a single thread. As you might guess in a chapter about using your cores, that last detail is a problem.

Reducers are an alternative way to express transformations over sequential data and feel similar to sequence function composition. However, reducers can execute those transformations in parallel using fork/join.

From Sequences to Reducers

Let’s consider a concrete example. A shipping company has data about all of the products that it needs to ship right now. Each product ...

Get Clojure Applied 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.