Returns a stateful hierarchical reducer.
Returns a stateful hierarchical reducer. This is used by the reduce operation internally. The reducer will perform as many reduce steps as possible every time a new element is added. It will retain at most 32 non-reduced elements, which will all be combined once the result() method is called.
the element and result type
the reduce operation. Must be associative
a stateful reducer that can be fed elements by calling apply
Reduces any traversable collection hierarchically.
Reduces any traversable collection hierarchically.
the element and result type
a traversable collection to be reduced
the reduce operation. Must be associative
an opt containing the result, or Opt.empty[T] if the collection is of size 0
Reduces an array hierarchically.
Reduces an array hierarchically.
the element type
the elements to reduce
the reduce operation. Must be associative
an opt containing the result, or Opt.empty[T] if the array is of size 0
A helper object to reduce collections using an associative operation and to produce stateful reducer objects.
Instead of aggregating from the left to the right, the result will be aggregated from the bottom to the top. E.g. for a sequence Array(1,2,3,4) and an operation (+), the reducers produced by this helper class would execute (1 + 2) + (3 + 4) instead of (((1+2)+3)+4). This can have significant advantages when the cost of an operation depends on the weight of an element.
Consider string concatenation: concatenating a sequence of one-char strings of size N using seq.reduceLeft(_ + _) would be an O(N**2) operation. Reducing it hierarchically would be an O(N*log(N)) operation.