easier work with collections: default Stream.toList?
stephane.demurget at free.fr
stephane.demurget at free.fr
Sun Sep 29 14:18:36 PDT 2013
I'm not suggesting to actually implement toList() and groupBy() in the Stream hierarchy itself.
We are talking about simple shortcuts to .collect(Collections.xxx()) here, nothing fancy.
--Stéphane
----- Mail original -----
> De: "Paul Benedict" <pbenedict at apache.org>
> À: "Zhong Yu" <zhong.j.yu at gmail.com>
> Cc: "stephane demurget" <stephane.demurget at free.fr>, lambda-dev at openjdk.java.net
> Envoyé: Dimanche 29 Septembre 2013 18:31:17
> Objet: Re: easier work with collections: default Stream.toList?
>
>
> I think, at one time, someone recommended toArray() and Brain said
> this would obviously fail with infinite streams. Wouldn't toList()
> bring the same consequences?
>
>
>
>
> On Sun, Sep 29, 2013 at 10:53 AM, Zhong Yu < zhong.j.yu at gmail.com >
> wrote:
>
>
> +1
>
> >From my own experience, I'd definitely love to see a Stream.toList()
> >method.
>
> Zhong Yu
>
>
> On Sat, Sep 28, 2013 at 4:21 AM, < stephane.demurget at free.fr > wrote:
> > 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
> >
>
>
>
>
> --
>
> Cheers,
> Paul
More information about the lambda-dev
mailing list