Simplified version of Stream.fold?
Gernot Neppert
mcnepp02 at googlemail.com
Wed Nov 28 06:54:20 PST 2012
Hello,
I propose to add a simplified version of Stream.fold.
The current "fold" version is very sophisticated and covers all possible
scenarios, but my experience with a similar expression-driven framework
indicates that a simpler version suffices in the vast majority of usecases:
<U> U fold(U base, Combiner<U,U,T> reducer);
Note that this would make
T reduce(T base, BinaryOperator<T> op);
redundant, so it could possible be removed from the interface.
example:
int totalOrders = customers.stream().fold(0, (s, c) -> s + c.getOrders());
As a sidenote, I'm curious why wildcard types on the Functor arguments have
been used in some, but not all of Stream's methods. "fold" and "reduce",
for example, do not use wildcard arguments, whereas "reduceBy" uses them to
its advantage.
More information about the lambda-dev
mailing list