Additional Collectors
Tim Peierls
tim at peierls.net
Wed Apr 3 10:49:40 PDT 2013
On Wed, Apr 3, 2013 at 1:27 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
> People also expressed concern that the "toMap()" (nee mappedTo,
> joiningWith) is not flexible enough. As a reminder, what toMap does is
> take a Stream<T> and a function T->U and produces a Map<T,U>. Some people
> call this "backwards"; they would rather have something that takes a
> Stream<T> and function T->K and produces a Map<K,T>. And others would
> rather have something that takes two functions T->K and T->U and produces a
> Map<K,U>.
>
The second form (Stream<T> and T->K producing Map<K, T>) could be called
"indexing", so toIndexMap or toIndex would seem appropriate. I don't have a
sense of a natural name for the third form. toMap still seems good for the
first form.
> All of these are useful enough. The question is how to fit them into the
> API. I think the name "toMap" is a bit of a challenge, since there are
> several "modes" and not all of them can be easily handled by overloads.
> Maybe:
>
> toMap(T->U) // first version
> toMap(T->K, T->U) // third version
>
> and leave the second version out, since the third version can easily
> simulate the second?
>
Maybe, but I like the thought of toIndex or something like that.
--tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/lambda-libs-spec-experts/attachments/20130403/488e27e2/attachment.html
More information about the lambda-libs-spec-experts
mailing list