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

Add groupBy() method to filter lists according to a critieria

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0-JSR-6
    • 1.0-RC-1
    • groovy-jdk
    • None

    Description

      Regroup elements according to a closure criteria inside a map index by the value of the criteria.

      def expected = [Integer: [1, 2], String: ["a", "b"], BigDecimal: [3.5, 4.6]]

      def list = [1, "a", 2, "b", 3.5, 4.6]

      def result = list.groupBy

      { it.class }

      assert [1, 2] == result[Integer]
      assert ["a", "b"] == result[String]
      assert [3.5, 4.6] == result[BigDecimal]
      assert 3 == result.size()

      Attachments

        Activity

          People

            guillaume Guillaume Sauthier
            guillaume Guillaume Sauthier
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: