Encounter order

Brian Goetz brian.goetz at oracle.com
Fri Oct 26 05:40:37 PDT 2012


>> People don't expect ordering of the *keys*, and that's fine.  What I
>> was talking about was ordering of the values, since the Map returned
>> is a Map<K, Collection<V>>.
> Your reduceBy() looked like this:
>
> <U, W> Map<U, W> reduceBy(...)
>
> no collections anywhere. Was that a mistake?

groupBy returns a Map<K,Collection<T>>.

reduceBy returns a Map<K,W>, because instead of accumulating elements in 
a K bucket and sticking them in a collection, we reduce all the elements 
in the K bucket.

For example:

   Map<Author, Document> longestDocByAuthor
     = docs.reduceBy(Document::getAuthor,
                     (d1, d2) -> (d1.length() > d2.length() ? d1 : d2));



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