[ 
https://issues.apache.org/jira/browse/GROOVY-2456?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17468593#comment-17468593
 ] 

Paul King commented on GROOVY-2456:
-----------------------------------

True, that is what many folks might expect. I think this is a Groovy 5 thing 
and we'd make a true operator overload, perhaps {{isIn}} to align with 
{{isCase}}. The default implementation of {{isIn}} could be implemented using 
{{isCase}} with the {{contains}} implementation for {{CharSequence}}. For 
earlier Groovy versions the workaround might be something like:
{code}
String.metaClass.isCase = {
    arg -> delegate.contains(arg)
}
println 'an' in 'banana'
{code}
It would need to be applied judiciously to not interfere with switch 
statements. In Groovy 5, there would be no need for the trick but it could be 
reverted back with a similar trick in reverse, i.e. on {{isIn}}, with much less 
chance of an adverse impact.

> Support in-Keyword for Strings
> ------------------------------
>
>                 Key: GROOVY-2456
>                 URL: https://issues.apache.org/jira/browse/GROOVY-2456
>             Project: Groovy
>          Issue Type: New Feature
>          Components: groovy-jdk
>    Affects Versions: 1.5.1
>            Reporter: Bernd Schiffer
>            Priority: Major
>
> assert 'abc'.contains('a') //1
> assert 'a' in ('abc'as List) //2
> assert 'a' in 'abc' //3 this breaks
> You ask a string if a substring is contained in it (//1). You can do that 
> with the in-Keyword with Lists (//2), too. But you can't do this with the 
> in-Keyword with Strings. It would be a consistent behaviour from Groovy if 
> you could do //3.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to