+1 for that, in some cases it is exactly what one needs, and it would be good to have native support for this in Groovy.

Thoughts:

1. Maybe put the "s" in front as in "scollect" ? This makes it quicker
   to get the result with Intellisense (type "sco" instead of
   "collects") and avoids having method names which imply meaning that
   is not there ("an object 'collects' something (i.e. rocks), instead
   of "this is the command to collect").
2. Would it make sense to only have to use the "s"-method for the first
   call in the call chain, since e.g. "grep" than already sees a stream
   anyway ?
3. ...and if yes, would a "streamify" operator be a better option (e.g.
   foo.>>collect { it * 2 }.grep { it > 10 }.take(3) ) ?

If the idea is to shift things over to using Java 1:1 for streams, then I think we should consider introducing alias methods that follow the Java naming convention for their non-streaming Groovy counterparts (collect/etc) (that might be a good idea any way)...

Cheers,
mg


On 24/05/2019 06:48, Simon Sadedin wrote:
On Fri, May 24, 2019 at 10:28 AM Paul King <pa...@asert.com.au <mailto:pa...@asert.com.au>> wrote:

    Also, if you have anything you'd particularly like to see in
    Groovy 4, please discuss. I'll have a slide on potential things in
    Groovy 4 in my gr8conf talk next week. I'd like to include as many
    sensible ideas as possible to make use of the opportunity to
    garner feedback on what our users are looking for.

    Some of the things currently on my list:
    * improved module support (including split package final steps)
    * further invoke dynamic improvements (including deferred merge to
    indy only)
    * stream-based replacements for XmlSlurper et al
    * groovydoc rework (assuming we manage to finish porting the
    current groovydoc to 3)
    * improved built-in type checking extensions (@NonNull et al)


I am wondering if there would be receptiveness to adding streaming based versions of Groovy's standard collection methods. ie: currently

foo.collect { it * 2 }.grep { it > 10 }.take(3)

fully evaluates the collect, then fully evaluates the grep, finally only to take 3 results. Java streams now solves this as do other languages (python generators, etc), but in Groovy you have to abandon the "groovy" methods and use Java streams (which works somewhat).

I could imagine this could be done just by adding 's' to all the methods:

foo.collects { it * 2 }.greps { it > 10 }.takes(3)

Of course people might find that a bit ugly and there could be different syntaxes or solutions .... but it would be really nice to have this "natively" in Groovy!

Cheers,

Simon





Reply via email to