[
https://issues.apache.org/jira/browse/GROOVY-10026?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17318521#comment-17318521
]
Eric Milles commented on GROOVY-10026:
--------------------------------------
You can use the streams API in any Groovy source and mix closures or lambdas if
you find one more convenient. So you could have:
{code:groovy}
def employeeStream = employees.stream()
.filter{ it.qualification == 'intern' }.sorted{ daysBetween(it.hired, now) }
if (monitorTop5Interns) {
print employeeStream.limit(5).toList()
}
{code}
Is there a specific shorthand/syntax you're looking for? We can certainly add
an extension method here or there, like "toList()" is short for
".collect(Collectors.toList())". I think the bigger concern is supporting the
existing Groovy extensions and Java streams and then adding a 3rd solution.
> 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
> Priority: Minor
> Labels: collections, evaluation, gdk, lazy, publish, stream,
> subscribe
>
> 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)