Collectors inventory

Brian Goetz brian.goetz at oracle.com
Mon Jun 17 12:56:27 PDT 2013


> Also to discuss: the no-identity version of reducing, as well as
> min/max, could now return Optional (they couldn't before.)  While the
> likelihood of them actually being applied to an empty stream is
> considerably lower than for the corresponding methods on Stream (because
> these methods are mostly for use as downstream reducers for things like
> groupingBy), it is possible that a user will use them directly.
> Currently they return null for empty streams.
>
> It seems "obvious" that we should make these bear Optional, but it also
> seems a shame, as this will impose a dramatic performance cost on any
> groupBy operation that uses them, because it means that every groupBy
> using them will be followed by a (sequential) Map.replaceAll.  So the
> combination of "higher cost" and "wouldn't ever happen in that case
> anyway" gives me some pause.

Actually, now that I look at the code, we are forced to do a 
post-transform anyway, since our internal accumulation form is a tuple 
of (valuePresent, value) anyway.  So the higher-cost objection is 
withdrawn, and making these return Optional would be more consistent 
with Stream operations.


More information about the lambda-libs-spec-experts mailing list