scala> val names = List("Peter", "Paul", "Mary")
names: List[String] = List(Peter, Paul, Mary)
scala> names.map(_.toUpperCase)
res12: List[String] = List(PETER, PAUL, MARY)
In this case, the underscore represents the only input argument, which is the element of names. This string is implicitly converted to StringOps and toUpperCase is invoked.
However, this does not work:
scala> names.map(StringOps.toUpperCase _)
<console>:14: error: value toUpperCase is not a member of object scala.collection.immutable.StringOps
names.map(StringOps.toUpperCase _)
I thought that this syntax is how I would get a reference to the function from the toUpperCase method.