Matching on tuple using comparison operator
pattern-matching, scala
Solution
The syntax is wrong, you should use guard as follows:
myTuple match {
case (-1,-1,true) => ...
case (x,-1,_) if x >= 0 => ...
case _ => ... // default
}
There are a lot of good introduction to scala pattern matching on the web. Here is the first detailed one, I've found on google: Playing with Scala's pattern matching
Problem
I would like to match on tuple pattern, but I can not find any solution how to match using comparison operators. My code is: ``` myTuple match { case (-1,-1,true) => ... case (_>=0,-1,_) => ... } ``` This gives give compile time error. I also tried to use if guard, but as I see it can not be applied this way: ``` case (_ if _>=0,-1,_) => ... ``` Is my approach correct or should I solve this on an different way? Thanks Zoltan