Collectors.collecting ?
Remi Forax
forax at univ-mlv.fr
Fri Jun 21 01:45:28 PDT 2013
Maybe the question is stupid, but I fail to understand why in collector API
we have a way to perform a reduction with no side effect but no way to
do the same thing with side effect
(in fact there is a way with the newly introduced methods 'of' but it's
verbose and not symmetric).
Currently we can write:
Arrays.stream(args).parallel().collect(
Collectors.groupingByConcurrent(arg -> arg,
Collectors.reducing(0, arg -> 1, Integer::sum)));
but neither
Arrays.stream(args).parallel().collect(
Collectors.groupingByConcurrent(arg -> arg,
Collectors.collecting(new MutableInt(), (arg, value) ->
value.increment())));
nor
Arrays.stream(args).parallel().collect(
Collectors.groupingByConcurrent(arg -> arg,
Collectors.collectingConcurrent(new LongAdder(), (arg,
adder) -> adder.increment())));
Rémi
More information about the lambda-libs-spec-experts
mailing list