Is it possible to do something like:
def foo(x: Int): Boolean = {
case x > 1 => true
case x < 1 => false
}
def foo(x: Int): Boolean =
x match {
case _ if x > 1 => true
case _ if x < 1 => false
}
Note that you don't have a case for x == 1 though...
I would write something like this:
def foo(x: Int) = if (x > 1) true
else if (x < 1) false
else throw new IllegalArgumentException("Got " + x)
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