Dario Arena created GROOVY-10026:
------------------------------------

             Summary: Update the GDK to better support java streams and 
Publish/Subscribe API
                 Key: GROOVY-10026
                 URL: https://issues.apache.org/jira/browse/GROOVY-10026
             Project: Groovy
          Issue Type: Improvement
    Affects Versions: 4.0.0-alpha-2
            Reporter: Dario Arena


Groovy is one of the first JVM languages to introduce "internal iteration" and 
in general collections operations like collect(), find(), collate().
Maybe now that java has streams and a publish/subscribe API some of this 
operations could be reworked and implemented using some of this features.
The first thing to improve could be a lazy evaluation of chained collections 
method calls, but without introducing in groovy the need to insert a "terminal 
operation" at the end of the chain.
Just as an example if i write something like

{quote}def employeeSorted = employee.findAll { it.qualification == 'intern' 
}.sort{ daysBetween(it.hired, now) }

if (monitorTop5Interns) {
    print employeeSorted.take(5)
}{quote}

When monitorTop5Interns is false there is no need to scan all the employee list 
to find all the interns because, at least at this point in time, 
"employeeSorted" is not evaluated. Even if it is true, because of the "take(5)" 
as the last operation once top 5 elements are found there is no need to scan 
the rest of the list.
Is it possible to implement some "intermediate decorator objects" that maybe 
extends they're correspective type (List, Set, Iterable, Collection...) that 
are automatically coerced to an actual concrete type (a java.util.ArrayList, a 
java.util.String...) only when they are actually evaluated (e.g. a 
"subscription" in the publish/subscribe semantics)?.
I know that for every collection one could call .stream() or wrap the 
collection in a "Producer" like in RxJava but wouldn't it be groovy-er if this 
is transparent for the users?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to