Let's declare a def and an equivalent function as a val:
scala> def optional(x:Int):Option[String] = None
optional: (x: Int)Option[String]
scala> val optional2:(Int)=>Option[String] = (i:Int) => None
optional2: Int => Option[String] = <function1>
Now why doesn't this work?
scala> List(1).flatMap(optional2)
<console>:9: error: type mismatch;
found : Int => Option[String]
required: Int => scala.collection.GenTraversableOnce[?]
List(1).flatMap(optional2)
^
While both of these do?
scala> List(1).flatMap(optional)
res4: List[String] = List()
scala> List(1).flatMap(optional2(_))
res5: List[String] = List()
Since Option is not a subtype of GenTraversableOnce, I think this must have something to do with implicits, but I can't figure out what exactly it is. I am using Scala 2.9.1.