More useful pattern matching

Look, I am not trying to be antagonistic here. But my reading of the language specification is that patterns are not expressions, they just try to look similar:
Expressions | Scala 3.4
Pattern Matching | Scala 3.4

I think we have different reasons on why this might be a useful feature to have, so I’ll not distract the discussion with my view anymore.

Yes, that is technically correct. Nevertheless, in a pattern like Right(foo), the identifier Right refers to an object whose unapply method is going to be called, and I find it a strange restriction that arbitrary expressions are not allowed there.

The main blockage is to avoid the ambitious. For example:

case A(x)(y)(z) => …

we can’t tell which one applies:

case A.unapply(x)(y)(z)
case A.apply(x).unapply(y)(z)
case A.apply(x)(y).unapply(z)

2 Likes