It’s obvious that Scala’s pattern matching allow destructuring or better say deconstructing objects, coming from a JS context, seems strange that destructuring cannot be used outside pattern matching, for example in lambdas or var declarations. Is something like that even possible/desirable in Scala? with the idea in mind that pattern matching has a different and more general mechanism than just only extracting fields.
Notice that Kotlin supports destructuring for both lambdas and declarations, on the other hand that it does not support destructuring for when expressions, the closest analogue of pattern matching.
If yes, that’s nice to hear!
I think it would be very interesting to know why you thought this was not possible, as this might indicate tutorials/articles/… do not give the correct impression
If not, then maybe you can clarify so we can discuss the benefits/drawbacks of a different approach
Would like to match kotlin’s less verbose syntax which works for any kind of class (instead of just case/data classes) in both lambdas and val/var declarations, by using the same syntax for destructuring both, fields and tuples