easier work with collections: default Stream.toList?
Paulo Silveira
paulo.silveira at caelum.com.br
Tue May 7 14:47:26 PDT 2013
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