On using even() is it so that it only matches the true condition from the unapply and on using even , how does this still prints "Is even"
object even{
def unapply(arg: Int): Boolean = (arg%2 == 0)
}
object singleDigit{
def unapply(arg: Int): Option[Boolean] = {
if(arg < 10) Some(true)
else None
}
}
val n = 9
n match {
case even() => println("Is even")
case singleDigit => println("is single")
case _ => println("No property")
}
//This gives "is single"
n match {
case even => println("Is even")
case singleDigit => println("is single")
case _ => println("No property")
}
//This gives "Is even"
How is even case satisfied here being n=9 as an odd number ? what is the difference between even and even() inside this pattern matching?