Stream operations -- current set
Henry Jen
henry.jen at oracle.com
Sun Oct 7 22:11:09 PDT 2012
On Oct 7, 2012, at 10:52 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
>>> <U> MapStream<T, U> mapped(Mapper<? super T, ? extends U> mapper);
>> From my experience, the opposite one is much more useful:
>> <U> MapStream<U, T> mapped(Mapper<? super T, ? extends U> mapper);
>> Are we implying that in this case one should use groupBy() (create many pointless collections) and then map() to throw the collections away?
>
> That works, but cheaper is:
>
> foos.mapped(mapper).swap()
>
> which transposes keys and values (probably needs a better name.)
This is also my experience. I am guessing the concern is there is no guarantee the mapper will ensure one-to-one mapping to maintain the key uniqueness in a Map as you mentioned as implying.
Brain's suggestion is a reasonable alternative if we know the result is unique and cost is pretty much nothing as swapping happens during iteration.
Cheers,
Henry
More information about the lambda-libs-spec-observers
mailing list