I am still studying Scala, but I believe that what happens is that you define a partial function that takes one argument. When calling methods such as List.map or List.foreach, which require only one argument, you can omit the underscore or the name val.
An example of the oval name val in closure:
val v = List("HEY!", "BYE!") v.foreach { Console.println }
This is the same as:
val v = List("HEY!", "BYE!") v.foreach { Console.println _ }
Using anonymous val:
val v = List("HEY!", "BYE!") v.foreach { Console.println(_) }
Or using the name val:
val v = List("HEY!", "BYE!") v.foreach { x => Console.println(x) }
Your closure uses a partial function (case statement) that takes an anonymous variable and immediately turns it into a tuple associated with two separate variables.
I guess I went up one of the fragments above. When I get to my work computer, I will check in the REPL.
Also, look at the Currying function in Scala for more information.
source share