December 2000
Intermediate to advanced
816 pages
16h 57m
English
The final functional programming piece is reduce(), which takes a binary function (a function that takes two values, performs some calculation and returns one value as output), a sequence, and an optional initializer, and methodologically “reduces” the contents of that list down to a single value, hence its name.
It does this by taking the first two elements of the sequence and passing them to the binary function to obtain a single value. It then takes this value and the next item of the sequence to get yet another value, and so on until the sequence is exhausted and one final value is computed.
You may try to visualize reduce() as the following equivalence example:
reduce(func, [1, 2, 3]) ≡ func(func(1, 2), 3)
Some argue that the ...
Read now
Unlock full access