You can't use such syntax in pattern matching. But here are two options -- first one is to use guards:
def bar = (p: FooPosition) => p match {
case FooPosition(x, _) if (x == p.x - 1) => -1
case _ => 0
}
Here _ denotes anything, I don't care about the actual value.
Second is to do match-by-value (values with capitalized name will be matched by it's value, instead of producing new alias):
def bar = (p: FooPosition) => {
val Px = p.x - 1
p match {
case FooPosition(Px, _) => -1
case _ => 0
}
}
Finally, your code will always default to 0 -- you're feeding some point p
to it and then expecting it's X coordinate to be one unit less. Perhaps, you should write
def bar(p: FooPosition) = p match {
case FooPosition(x, _) if (x == p.x -1) => -1
case _ => 0
}
instead