Question about Iterable.reduce signature

Olexandr Demura oleksander.demura at gmail.com
Tue May 22 04:05:03 PDT 2012


Do I understand right?
Point of 'reduce' accepts (T,T)->T is to have same signature
T reduce(T base, Operator<T> reducer)
in unrelated hierarchies of Iterable and Splittable
instead of separate
<U> U reduce((T, U)->U onNode, U onEnd) for sequential Iterable
(should it be Sequence than?)
<U> U reduce((T, U, U)->U onNode, U onEnd) for parallel Splittable
(should it be Tree than?)
(except Splittable doesn't have marker of structure end -
.iterator().hasNext() should not be)

> What you are suggesting is to fuse mapping and reducing into a single
> operation.  While this often makes sense, the approach you suggest gets
> more difficult when you want to execute in parallel.
>
> If you define your reducer over T as a (T,T) -> T (assuming
> associativity), then to compute the reduction in parallel, you can
> decompose your collection into chunks, reduce each chunk to a T, and
> then reduce the reduced values up the tree until you have a single T.
>
> If you define your reducer as a (T,U) -> U, you can reduce each chunk to
> a U, and then you have no way to combine the per-chunk Us into a single
> answer.


More information about the lambda-dev mailing list