It's interesting to see that the two higher-order functions that form the map/reduce pattern, one of the most commonly known patterns in functional programming, ended up in two different header files in C++. The transform/accumulate combination, requiring both the <algorithm> and the <numeric> header files, allow us to solve many problems that have the following pattern:
- A collection is provided.
- The collection needs to be transformed into something else.
- An aggregated result needs to be computed.
Let's look at a few examples.