Book Image

Clojure High Performance Programming, Second Edition - Second Edition

By : Shantanu Kumar
Book Image

Clojure High Performance Programming, Second Edition - Second Edition

By: Shantanu Kumar

Overview of this book

Table of Contents (15 chapters)
Clojure High Performance Programming Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Parallelism with reducers


Reducers are a new abstraction introduced in Clojure 1.5, and are likely to have a wider impact on the rest of the Clojure implementation in the future versions. They depict a different way of thinking about processing collections in Clojure—the key concept is to break down the notion that collections can be processed only sequentially, lazily, or producing a seq, and more. Moving away from such a behavior guarantee raises the potential for eager and parallel operations on one hand, whereas incurring constraints on the other. Reducers are compatible with the existing collections.

For an example, a keen observation of the regular map function reveals that its classic definition is tied to the mechanism (recursion), order (sequential), laziness (often), and representation (list/seq/other) aspects of producing the result. Most of this actually defines "how" the operation is performed, rather than "what" needs to be done. In the case of map, the "what" is all about applying...