How would I do a `when` on two items? Use a `Pair`...
# functional
r
How would I do a
when
on two items? Use a
Pair
and deconstruct using
to
?
e
unfortunately you lose several features that way - no nested destructing, no exhaustiveness checks
b
There are some issues about better exhaustiveness checking (without when-with-subject). So I think when conditions on local vals is your answer, with exhaustiveness and smart cast improvements over the horizon: https://youtrack.jetbrains.com/issue/KT-63696/Improved-exhaustiveness-checking > Another use case where the current matching is not good enough is when the condition depends on more than one variable. This is very common in combination with nullability: >
Copy code
val x: A? = thingThatMayReturnNull()
val y: B? = thingThatAlsoMayReturnNull()
when {
    x == null && y == null -> ...
    x != null -> ...
}