Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
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
- links to