I see the following code in several places depicting the use of partial functions in Scala.
val divide: PartialFunction[Int, Int] = { case d: Int if d != 0 => 42 / d } Here, divide is a variable whose type of is PartialFunction[Int,Int] which is a trait. I am confused about the RHS part. Since the type of the variable "divide" is: PartialFunction[Int,Int] , it needs to be instantiated by using a "new" keyword. I am not sure about the kind of syntax this is. Plus how isdefined() function automatically defined above ? ( isDefined() seems available; but it is there hidden).
Can someone please help.
new, the compiler can create objects directly for literals (0,"Hello") or indeed when it creates a function (which is just an instance of aFunctionclass). In this case it creates an instance ofPartialFunctionusing that syntax.