Here are a few things going on.
First, of all the syntax of the parameter builder, you can use it only in the outer parentheses of the lambda definition. It cannot be used in parentheses of method calls that you execute in a lambda definition.
Here is an example to demonstrate this point.
val a = (1 to 10).map(_ + 1)
This will work.
val b = (1 to 10).map(math.sin(_ + 1))
This will not work.
Therefore, your code does not use the parameter linker syntax at all. Instead, it uses partially applied functions.
for instance
(1 to 10).foreach(println _)
functionally equal
val a = println (_ : Int) (1 to 10).foreach(a)
Also, when a method name is used in a lambda expression, the underscore may be omitted. Scala will still generate a partially applicable method.
therefore
(1 to 10).foreach(println)
equally
(1 to 10).foreach(println _)
And so your code is equal
val a = println (_ : Int) (1 to 10).foreach{ a a }
And since {aa} returns a, it equals
val a = println (_ : Int) (1 to 10).foreach(a)
source share