August 2015
Intermediate to advanced
220 pages
5h 53m
English
The reduce function reduces a collection to a value by repeatedly applying a function to an accumulated value and the next element in the collection, using an optional initial value. The into function is a special case that reduces a collection to another collection instead of a simple value.
For example, in our space simulation, consider computing the total number of moons across all planets in the solar system. We need to first extract the number of moons for each planet (a mapping transformation), then reduce those to a single value (the total) by using the + function. The reduce function is often used to combine a collection transformation with a reduction step.
We can compute the total for a collection of planets using ...