[
https://issues.apache.org/jira/browse/GROOVY-9848?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17733764#comment-17733764
]
Paul King commented on GROOVY-9848:
-----------------------------------
[~blackdrag] Current behaviour is the latter of your stated expectations.
So, "in" for a Map currently means the map has the key with some true (as per
Groovy truth) value, i.e.:
{code}
def map = [a:false, b:true]
assert 'a' !in map
assert 'b' in map
{code}
The implications for switch are that a match will occur for the first map case
containing the switch value as key and non-null/zero/empty value, i.e.:
{code}
assert 'e' == switch('foo') {
case [bar: true] -> 'a'
case [foo: false] -> 'b'
case [foo: null] -> 'c'
case [foo: ''] -> 'd'
case [bar: false, foo: 42] -> 'e'
default -> 'f'
}
{code}
We could change this behavior but it would be a breaking change. I imagine
current usage is minimal (almost a seldom-used edge case) but I am not sure
having the alternative key-only definition would suddenly make this become
widely used. But if folks have real-life commons use cases where this change
would greatly simplify the complexity of the overall code, it would be nice to
see the examples and we could think about the change for Groovy 5.
> 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)