[
https://issues.apache.org/jira/browse/GROOVY-9848?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17298973#comment-17298973
]
Eric Milles edited comment on GROOVY-9848 at 4/16/23 4:14 PM:
--------------------------------------------------------------
Update: Groovy 4.0.1 (GROOVY-7802) added extension "map.withDefault(autoGrow,
autoShrink) \{ ... \}" so that it is possible to use "in", "get" or "getAt"
without mutation. As noted above, membership (aka "isCase") implements the
semantic "map.get(k) as boolean". Below are excerpts from
{{DefaultGroovyMethods}}.
{code:java}
public static boolean isCase(Map caseValue, Object switchValue) {
return
DefaultTypeTransformation.castToBoolean(caseValue.get(switchValue));
}
public static boolean isCase(Collection caseValue, Object switchValue) {
return caseValue.contains(switchValue);
}
{code}
"item in list" is implemented in terms of {{contains}}, so the proposal to
implement map membership in terms of {{containsKey}} seems reasonable. The
only concern in my mind is backwards compatibility. [~paulk] Do you think
there is any path forward where {{isCase(Map,Object)}} can return
"caseValue.containsKey(switchValue)"?
was (Author: emilles):
GROOVY-7802 requests {{withDefault}} not mutate the underlying map.
> Allow membership operator to work on maps
> -----------------------------------------
>
> Key: GROOVY-9848
> URL: https://issues.apache.org/jira/browse/GROOVY-9848
> Project: Groovy
> Issue Type: Improvement
> Reporter: Keegan Witt
> Priority: Major
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)