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

Improve docs for Collection.groupBy and add new Collection.collate(Closure) [Small breaking change]

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0
    • 1.5.2
    • None
    • None

    Description

      The documentation for Collection.groupBy is a little ambiguous in that it does not make it absolutely clear that the return value is a Map of keys pointing to values that are ArrayLists.

      A new method, Collection.collate(Closure) would be a nice addition, to allow collation of a collection of objects into a map keyed on some value provided by a closure, without returning a List for every value. This might be implemented so:

      java.util.Map collate(Closure collator) {
          def result = [:]
          this.each() {
               result[collator.call(it)] = it
          }
      }
      

      Attachments

        Activity

          People

            paulk Paul King
            marc@anyware.co.uk Marc Palmer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: