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
?
To extract data with different criteria or conditions in Microsoft Excel, the combination of INDEX and MATCH functions is best suited so far. In this article, you'll get to learn how you can use these INDEX and MATCH functions together with 3 different criteria in Excel with proper illustrations.
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 }
Following on from my comments to Easy Angel's answer, I still feel this
if (c == 0) b -a else if (c > 9) 0 else if (a == b) 0 else 1 // your logic here
is clearer. Basically because there isn't really any pattern to match here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With