Scala pattern matching, check if number is greater than

Possible duplicate:
Using comparison operators in Scala pattern matching

For the method below, I get the error: "'=>' the expected but integer literal was found."

It is not possible to check if x is larger than another number, or is there an alternative approach for returning "greater than 2" if "> 2" matches?

def describe(x: Any) = x match { case 5 => "five" case > 2 => "greater than 2" } 
+4
source share
1 answer

Try:

 def describe(x: Any) = x match { case 5 => "five" case x: Int if (x > 2) => "greater than 2" } 
+8
source

Source: https://habr.com/ru/post/1441633/


All Articles