I am wondering if it is possible to use currying on multi parameter-group functions :
scala> def sum(a: Int)(b: Int): Int = { a+b }
sum: (a: Int)(b: Int)Int
scala> sum(3)(4)
res2: Int = 7
scala> val partFunc = sum(3) _
partFunc: Int => Int = <function1>
scala> partFunc(4)
res3: Int = 7
scala> val partFunc2 = sum _ _
<console>:1: error: ';' expected but '_' found.
val partFunc2 = sum _ _
^
scala> val partFunc2 = (sum _) _
<console>:8: error: _ must follow method; cannot follow Int => (Int => Int)
val partFunc2 = (sum _) _
Writing simply
sum _does not yet have anything to do with the arguments ofsum, but simply distinguishes the function objectsumfrom an application of the function.Hence, you can write:
As you can see from the type information, this is already the curried version of
sumwhich takes twoIntparameters.Of course, you can then proceed as before with
partFunc2(4)being of typeInt => Intand so on.