easier work with collections: default Stream.toList?

Sam Pullara spullara at gmail.com
Tue May 7 15:16:24 PDT 2013


I think Javadocs around .collect() should be sufficient. Additionally,
I think the IDEs will adapt to some of the new kinds of APIs and will
offer up these methods when they see an opportunity.

Sam

On May 7, 2013, at 3:07 PM, Paulo Silveira <paulo.silveira at caelum.com.br> wrote:

> Hello Brian and lambda developers.
>
> Given a List<User> users, before the API  'streamification' we could do:
>
> List<user> filteredList = users.filter(p -> p.getPoints() > 50);
>
> After the API streamification, things got bigger:
>
> users.stream().filter(p -> p.getPoints() > 50).collect(Collectors.toList());
>
> I do understand the benefits from the API, but it could be easier with
> some default methods on Stream:
>
> users.stream().filter(p -> p.getPoints() > 50).toList() (or collectToList())
>
> I am aware that you want to avoid trivial default methods, but these
> ones could help a lot. It is a strange argument, but new programmers
> are much more attracted to use and study methods which are easy to
> invoke. A Collector is not a 'user friendly' interface, and there will
> be no big clues to the Collectors factory when a developer is
> exploring the api through an IDE.
>
> The best of all worlds (at least for lazy programmers such as me)
> would be to have a default Collection.filter/map/... that delegates to
> stream().filter/map/.collect(intoX()), making the old api approach
> available. 0 chance?
>
> Regards
>
> --
> Paulo Silveira
> www.caelum.com.br
> www.casadocodigo.com.br
>


More information about the lambda-dev mailing list