Does anyone know if I can apply `when` on a `pair`...
# announcements
w
Does anyone know if I can apply
when
on a
pair
type? Finding it a bit difficult to make it work. Something like:
Copy code
val pair: Pair<StatusAType, StatusBType> = ...
when(pair) {
            is (StatusA, StatusB) -> {

            }

        }
It is showing an error
Type Expected
in IDE
s
are you trying to check the type? or the value?
j
are you trying to short-hand
pair.first is StatusA && pair.second is StatusB
?
w
@jon.peterson This is not working ☝️
@snowe I am trying to check values.
a
@Wahib https://kotlinlang.org/docs/reference/multi-declarations.html Kotlin doesn't support destructuring inside
when
(yet?)
w
yeah seems like it. Any kotlin workarounds I can use? Maybe like putting values to map and reading from there? It is an async operation which receives a pair after a
zip
operator
Is it just me or the guy gave an impression that checking for
Pair(x, y)
is possible with
when
?
Copy code
when(obj) {
    Pair("a", 10) -> ...
    Pair("c", 13) -> ...
    else -> ...
}
https://discuss.kotlinlang.org/t/destructuring-in-when/2391
l
You can also use the
to
infix extension function in
when
branches