when (test(_) == MyThing.ONE) {
"hello" -> { /* ... */ }
"hi" -> { /* ... */ }
"greetings" -> { /* ... */ }
"yo" -> { /* ... */ }
}
Now for each entry, it would be evaluated with the argument from _
.
If you broke it down to another when statement, it would look like this.
when (MyThing.ONE) {
test("hello") -> { /* ... */ }
test("hi") -> { /* ... */ }
test("greetings") -> { /* ... */ }
test("yo") -> { /* ... */ }
}
This feature could perhaps go into multiple when arguments too.
when (test(_).func(_) == MyThing.ONE) {
"hello", 30 -> { /* ... */ }
"hi", 20 -> { /* ... */ }
"greetings", 50 -> { /* ... */ }
"yo", 10 -> { /* ... */ }
}
There’s a discussion about adding pattern matching here that you might be interested in:
There’s also a new #pattern-matching channel on the Kotlin Slack