You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by "Milles, Eric (TR Technology) via dev" <de...@groovy.apache.org> on 2022/12/19 14:29:54 UTC

RE: [EXT] Possible additional DGM collectEntries variants

True, no direct equivalents for associateBy and associateWithValue.  But "collectEntries{ [it.toLowerCase(), it] }" is pretty succinct.

If you wanted to extend with just one new extension of collectEntries, I think ".collectEntries(keyFun, Function.identity())" and ".collectEntries(Function.identity(), valFun)" is the associateBy and associateWithValue.  Java streams gives you a lot of options here.  Guava provides "uniqueIndex" to do the same, but provides stronger checks on key uniqueness.  https://guava.dev/releases/23.0/api/docs/com/google/common/collect/Maps.html#uniqueIndex-java.lang.Iterable-com.google.common.base.Function-