How is this more powerful than rust match?
How is this more powerful than rust match?
Other useful features it has are that most constructions are also expresions. So you can assign the outcome of a when and not having a value for one of the branchesd then becomes a compile error. IMHO when is vastly superior to Java's switch. Something like that would also be a great addition to e.g. typescript which inherits limitations from Java's limited syntax.
Kotlin does have destructuring. You can do val (foo,bar) = returnsomePair(). Also works in lambdas when you do a foreach on e.g. map entries.
Kotlin checks exhaustivity of when only if it is used as an expression, not as a statement.
https://kotlinlang.org/docs/reference/control-flow.html#when...
Kotlin doesn't allow destructuring in when:
https://discuss.kotlinlang.org/t/destructuring-in-when/2391
This is just straight up weak coming from any reasonable ML derived language with real pattern matching.