What is the reason the second function does nor compile:
case class Person(name: String)
def f1(op: Option[Person]) = op.map(p => Seq(p.name)) // GOOD
def f2(op: Option[Person]) = op.map(Seq(_.name)) // WRONG
P.S. I see comments pointing stackoverflow.com/a/7673633/6059889 as an answer to the question, but I do not understand how this answers it. According to rule 2, I'd expect Seq(_.name)
to become x => Seq(x.name)
, which should work.
P.P.S. Thanks, Dima, for the link to: Underscore in Named Arguments: link to _ always picks the tightest non-degenerate scope it can, I get it.