Reduces the collection to a single value. Left-associative.
Example:
Vector.of("a", "b", "c").foldLeft("!", (xs,x) => x+xs);
=> "cba!"
The initial value
A function taking the previous value and the current collection item, and returning an updated value.
Reduces the collection to a single value. Right-associative.
Example:
Vector.of("a", "b", "c").foldRight("!", (x,xs) => xs+x)
=> "!cba"
The initial value
A function taking the current collection item and the previous value , and returning an updated value.
Reduces the collection to a single value by repeatedly calling the combine function. No starting value. The order in which the elements are passed to the combining function is undetermined.
Generated using TypeDoc
Reduces the collection to a single value using the associative binary function you give. Since the function is associative, order of application doesn't matter.
Example:
HashSet.of(1,2,3).fold(0, (a,b) => a + b); => 6