3 ms·
Reduce is also known as "fold" in other languages. https://en.wikipedia.org/wiki/Fold_(higher-order_function) https://en.wikipedia.org/wiki/Fold_(higher-order_
by rdtsc 7y ago
Reduce is also known as "fold" in other languages.
https://en.wikipedia.org/wiki/Fold_(higher-order_function) https://en.wikipedia.org/wiki/Fold_(higher-order_function)
And especially when using immutable data it can be used for iterating, traversal (lists and trees, like say an in-order fold), filtering and other things. But there it is not an just an nice trick like for JS, but it is the canonical way of doing things.
- saagarjha 7y agoReduce is slightly different from fold because it does not use an initial value, which means its semantics differ somewhat with regards to restrictions on types.
- hnra 7y agoReduce in Javascript has the initial value as an optional parameter.
- saagarjha 7y agoAnd it doesn't do types, so that's not really an issue either…
- johnday 7y agoFold does not always have an initial value either. The Wikipedia article linked in the post to which you responded says as much.
- saagarjha 7y agoSorry, I worded that poorly: fold usually does not have an initial value.