Scala has both functions and methods; they are not exactly the same thing.
def add(a: Int, b: Int, c: Int) = a + b + c
Defines a method (not a function !!).
val add2 = (a: Int, b: Int, c: Int) => a + b + c
What is the function add2 assigned (not the method !!).
The can not method will be the final value, and the function can:
scala> add <console>:9: error: missing arguments for method add; follow this method with `_' if you want to treat it as a partially applied function add ^ scala> add2 res1: (Int, Int, Int) => Int = <function3> scala> val a = add <console>:8: error: missing arguments for method add; follow this method with `_' if you want to treat it as a partially applied function val a = add ^ scala> val a2 = add2 a2: (Int, Int, Int) => Int = <function3>
Writing an underscore after the method name can explicitly convert the method to a function:
scala> add _ res2: (Int, Int, Int) => Int = <function3>
But if you write an underscore after the value, it is converted to a function that does not accept an argument with the return type:
scala> val s = "" s: String = "" scala> val i = 1 i: Int = 1 scala> s _ res3: () => String = <function0> scala> i _ res4: () => Int = <function0>
So, if the value itself is a function, writing an underscore after it receives a new function that does not accept an argument with the return type of the function:
scala> add2 _ res5: () => (Int, Int, Int) => Int = <function0>