November 2017
Intermediate to advanced
670 pages
17h 35m
English
Next, let's look at the Reduce function. Reduce is the Swiss army knife of HOFs. With a Reduce function, we can do anything that can be done with Filter or Map.
A Reduce function, also known as a fold, accumulate, aggregate, compress, or inject takes a seed value and applies the logic of the reducer function to the seed, and potentially multiple calls to itself to arrive at a result. Often, the reduce function will combine the data elements to return a single aggregated value, hence the term fold. So, we fold all of the data into a single result.
Back in main.go, we apply the ByMake filter to filter out all the cars that are not a Honda product. Then, we call the Reduce function to transform the collection of Honda vehicles ...