Is it possible to match on a comparison using the pattern matching system in Scala? For example:
a match {
case 10 => println(\"ten\")
case _ >
A solution that in my opinion is much more readable than adding guards:
(n compare 10).signum match {
case -1 => "less than ten"
case 0 => "ten"
case 1 => "greater than ten"
}
Notes:
0 if equal.compare to -1 for a negative number (less than 10), 1 for positive (greater than 10), or 0 for zero (equal to 10).