I have a function:
def func(a: int, b: int, c: double): int
And I want to match various possible scenarios
c
is 0, return b-a
c
> 9, return 0a=b
return 0And so on, before doing some more complex logic if none of the above are satisfied.
Do I have to match c separately first, or can I match on a,b,c, like _,_,0
?
You can pattern match all described cases like this:
def func(a: Int, b: Int, c: Double) = (a, b, c) match {
case (a, b, 0) => b - a
case (a, b, c) if c > 9 || a == b => 0
case _ => 1 // add your logic here
}