Give This YouTrack Issue A +1 If You'd Like Enhanced If Statements

https://youtrack.jetbrains.com/issue/KT-40222

You should explain your idea. Leaving just the link is not respectful to the community.

3 Likes

I explained myself on the issue, copying and pasting what I said there here just seems redundant.

The new operator you want to add is called xor and I don’t have much against it. I don’t remember using it much (except in bit operations) but sure, why not. However I don’t see this being added if bitwise operators aren’t added as well.

The other part is a nicer way to test if a value is equal to any one in a list of options. I like the idea of having something for this, but your syntax doesn’t work. It’s incompatible with boolean expressions.

Maybe something like would work instead.

if(someValue == (option1 or option2 or option3))

This could be done easily using infix functions.

2 Likes

I agree, something like that would be much better! You should leave a comment regarding that on the issue (Unless you’d like me to do so I’d be happy to).

For two inputs, there’s already a standard library function a xor b dedicated for that: xor - Kotlin Programming Language