can you use destructuring in when expressions? lik...
# getting-started
b
can you use destructuring in when expressions? like:
Copy code
data class Test(val a: String, val b: Int)

val x = Test("test", 3)

when (x) {
    is Test(a, b) -> println(a + b)
}
🚫 1
1
h
Sadly not, that's one place where Scala's pattern matching really did it better 😞
b
or Java xD
s
Copy code
when (x) {
  is Test -> with(x) { println(a + b) }
}
🫣 1
No destructuring required 👍
b
does that work in guard position?