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

Some DGM Collection improvements

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.4.0-beta-2
    • None
    • None

    Description

      Highlights of the proposed improvements:

      • The unique() DGM methods follow Java's default of mutate in place when called on for instance a Collection (but also has a boolean flag for non-mutating behavior). There is no Iterable variant of the method but if there was one, a mutate flag wouldn't make sense for non-Collection iterables. The Iterator variant has no flag and it wouldn't make sense anyway. There is no array variant but if there was one it wouldn't make sense to have a mutate flag. Rather than complicating unique further, this improvement adds Iterable, Iterator and array variants of toUnique. This method always returns new collection-like structures.
      • A similar situation exists for sort() as for unique. This improvement adds Iterable, Iterator, array and Map variants of toSorted. This method always returns new collection-like structures.
      • Some non-Iterable variants can be deprecated in favor of Iterable variants for: collate, containsAll, tail, take, multiply on Iterables, disjoint, minus on Iterables.
      • The non-released List variants for init(), takeRight and dropRight have been elided (they provided only a marginal performance benefit compared to extra API complexity) and Iterator variants have been added.
      • The returned collection type is kept similar to the original where possible for the Iterable variants of: tail, init, take, takeRight, drop, dropRight, takeWhile, dropWhile, multiply on Iterables.
      • There are two new addAll variants on Collections: addAll(Iterator) and addAll(Iterable).
      • Where possible Iterator variants of the above mentioned methods have been modified (where necessary) so that they don't create extra copies of collection-like structures (i.e. Iterators are used instead of logic involving for example toList followed by operations on the list). This makes them work better with (possibly infinite) streams of data, e.g.:
        int a = 1
        def infiniterator = [ hasNext:{ true }, next:{ a++ } ] as Iterator
        assert infiniterator.drop(3).dropWhile{ it < 9 }.toUnique{ it % 100 }.init().tail().take(3).toList() == [10, 11, 12]
        

      Attachments

        Activity

          People

            paulk Paul King
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: