Pattern 14Filter-Map-Reduce

Intent

To manipulate a sequence (list, vector, and so on) declaratively using filter, map, and reduce to produce a new one—this is a powerful, high-level way of doing many sequence manipulations that would otherwise be verbose.

Overview

The way we manipulate sequences in a procedural language is more closely related to the way a computer works than to the way humans think. Iteration is a step above the dreaded goto statement, and it’s intended to be easily translated into machine code more than it’s intended to be easy to use.

Filter-Map-Reduce gives us a more declarative way to do many sequence manipulations. Instead of writing code that reorders or alters the elements in a sequence by working its way iteratively ...

Get Functional Programming Patterns in Scala and Clojure 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.