Is there a succinct way to check if an expression matches a given pattern? For instance, consider the following code:
val result = expr match {
SomePattern(_, 1, _) => true
_ => false
}
While this code works, it is fairly noise and long. I was wondering if there is a nicer way to achieve the same. It would be great if Scala had a matches
construct, that would allow one to write
val result = expr matches SomePattern(_, 1, _)
I would even consider writing a helper function to make something along those lines possible. However, that seems difficult to do, because I cannot pass a pattern as an argument as far as I know. Maybe something like this would be possible with macros that are available in Scala 2.10 (as experimental feature)?