easier work with collections: default Stream.toList?
Gernot Neppert
mcnepp02 at googlemail.com
Wed Oct 2 01:18:28 PDT 2013
Thumbs up for 'toList()'!
In our home-brewn Streaming framework, 'toList()' is the terminal operation
in the vast majority of all usecases. We have a more generic method
'into(Collection)' also, but we explicitly added 'toList()' because it was
so frequent!
I have to admit I don't understand the opponents' argument 'adding
toList() ties the Streaming API to the Collections API'. Both
java.util.Collection and java.util.streams.* will be part of the JDK for
years to come. It's not as if we were to abandon the Collections framework
in the foreseeable future, right?
(Like every API, it has it's quirks, but it's far from 'bad')
2013/9/28 <stephane.demurget at free.fr>
> hi guys,
>
> Brian, you mentioned back in May the possibility that the EG might
> consider adding a small number of convenience methods/shortcuts for
> collecting elements:
>
> http://mail.openjdk.java.net/pipermail/lambda-dev/2013-May/009798.html
> (can't reply as I was not subscribed at the time, sorry)
>
> I see the API freeze deadline is approaching, and I grasp the problem of
> opening more API demand or the intent to guide users to using Collectors
> entirely instead, but is there any hope?
>
> We have ~15 years of APIs all over the world accepting Collections and
> Maps, and I really think having those two:
>
> * .toList() -> .collect(Collections.toList())
> * .groupBy(classifier) -> .collect(Collections.groupingBy(classifier))
>
> would be a huge asset to use existing librairies smoothly, increasing
> readability and helping newcomers for the simplest and most common cases.
>
> I understand static imports can increase readability a bit, and IDE
> support will certainly help in that area, but until now they were no real
> API "requiring" this way of writing (and if you're not, it's really
> verbose). I'm confident having these shortcuts with javadoc to gently point
> users to collectors would be really more helpful and expected.
>
> I personally do not think .toSet() is worth it though.
>
> --Stéphane
>
>
More information about the lambda-dev
mailing list