easier work with collections: default Stream.toList?

Brian Goetz brian.goetz at oracle.com
Tue May 7 15:13:45 PDT 2013


This is something the EG has discussed -- a *small* number of 
convenience methods like toList() which simply expand to 
.collect(toList()).  The biggest challenge here is where to draw the 
line, and every additional one added just creates more fuel for the 
demand to add more, until the API is overwhelmed.  So if we can find a 
stable point with a small number (two or three) such conveniences that 
carry their weight, I wouldn't be averse.

On 5/7/2013 5:47 PM, Paulo Silveira 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