Why does the following work only using the format a => xxx to define a function?
Some("Help").foreach(p => println(p + " me"))
will produce the output "Help me", which is what I expect. On the other hand, the following code (which I see as equivalent)
Some("Help").foreach(println(_ + " me"))
results in an error at the underscore: missing parameter type for expanded function ((x$1: ) => x$1.$plus(" me")).
But the following (very similar)
Some("Help").foreach(println(_))
results in "Help" which is also the expected behavior.
In a 3rd attempt, I tried to specify the type, like this:
Some("Help").foreach(println((_: String) + " me"))
and the result was error: type mismatch; found : Unit; required: String => ?
So, what is going on? Why doesn't the underscore syntax work?