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

Potential additional DGM collectEntries variants

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 5.0.0-alpha-1
    • None
    • None

    Description

      As discussed in the mailing list:
      https://lists.apache.org/thread/7rd6wdblnh7bmdf6socjnbf21crg37g0

      Existing variants:

      var languages = ['Kotlin', 'Groovy', 'Java', 'Clojure']
      assert languages.collectEntries{ [it.toLowerCase(), it.size()] } ==
          [kotlin:6, groovy:6, java:4, clojure:7]
      assert languages.collectEntries{ [it.toLowerCase(), it] } ==
          [kotlin:'Kotlin', groovy:'Groovy', java:'Java', clojure:'Clojure']
      assert languages.collectEntries(Scala:5){ [it, it.size()] } ==
          [Scala:5, Kotlin:6, Groovy:6, Java:4, Clojure:7]
      

      Proposed new variants:

      assert languages.collectEntries(String::toLowerCase, String::size) == [kotlin:6, groovy:6, java:4, clojure:7]
      assert languages.withCollectedKeys(String::toLowerCase) == [kotlin:'Kotlin', groovy:'Groovy', java:'Java', clojure:'Clojure']
      assert languages.withCollectedValues([Scala:5], String::size) == [Scala:5, Kotlin:6, Groovy:6, Java:4, Clojure:7]
      def squared = e -> e ** 2
      assert [Scala:5, Kotlin:6, Groovy:6, Java:4, Clojure:7].collectEntries(String::toLowerCase, squared) ==
          [scala:25, kotlin:36, groovy:36, java:16, clojure:49]
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: