This chapter covers
- Recognizing the reduce pattern for N-to-X data transformations
- Writing helper functions for reductions
- Writing lambda functions for simple reductions
- Using reduce to summarize data
In chapter 2, we learned about the first part of the map and reduce style of programming: map. In this chapter, we introduce the second part: reduce. As we noted in chapter 2, map performs N-to-N transformations. That is, if we have a situation where we want to take a sequence and get a same-sized sequence back, map is our go-to function. Among the examples of this that we’ve reviewed are file processing (we have a list of files and we want to do something to all of them; discussed in chapter 4) and web scraping (we have a list of websites and we want to get the content for each of them; discussed in chapter 2).