Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10026

Update the GDK to better support java streams and Publish/Subscribe API

    XMLWordPrintableJSON

Details

    Description

      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

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

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

      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?

      Attachments

        Activity

          People

            Unassigned Unassigned
            darioarena87 Dario Arena
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: