In the book Functional Programming In Scala, there's an example of 'Lift' where a function with type A => B
is promoted to Option[A] => Option[B]
.
This is how lift is implemented:
def lift[A,B](f: A => B):Option[A] => Option[B] = _ map f
I have a couple of confusions regarding this:
The first one is, what is the '_' here? And secondly, when I remove the return type from the def, expecting the type-inference to do its magic I get the following exception:
scala> def lift[A,B](f: A => B) = _ map f
<console>:7: error: missing parameter type for expanded function ((x$1) => x$1.map(f))
def lift[A,B](f: A => B) = _ map f
Can somebody explain what's going on here?
Thanks