Combining the map and reduce transformations
In the other recipes in this chapter, we've been looking at map
, filter
, and reduce
operations. We've looked at each of these in isolation:
- The Applying transformations to a collection recipe shows the
map()
function. - The Picking a subset – three ways to filter recipe shows the
filter()
function. - The Summarizing a collection – how to reduce recipe shows the
reduce()
function.
Many algorithms will involve combinations of functions. We'll often use mapping, filtering, and reduction to produce a summary of available data. Additionally, we'll need to look at a profound limitation of working with iterators and generator functions; namely, this limitation:
An iterator can only produce values once.
If we create an iterator from a generator function and a collection of data, the iterator will only produce the data one time. After that, it will appear to be...