A simple function literal can be written as
def add(x : Int) = x + 2
In the above example I understand add is a function that takes an Int and gives an Int. Its type is add: (x: Int)Int
It is very clear.
But the below example which is of type Option[Int] => Int it is a bit unclear
scala> def matchFunction : Option[Int] => Int = {
| case Some(x) => x
| case None => 0
| }
matchFunction: Option[Int] => Int
In the second example, can anyone explain why the type should it not be
def matchFunction (x : Option[Int]) : Int
Also please explain what is the difference between the above function and the one below that uses match from a type perspective
def matchFunction (x : Option[Int]) : Int = x match {
case Some(x) => x
case None => 0
}