Reputation: 6541
In Scala, I could generate a curried function like so:
def multiply(m: Int)(n: Int): Int = (m + 1) * (n + 2)
If I wanted, I could generate a new function, by filling that first parameter, like so:
val timesTwo = multiply(1) _
But what is the syntax for replacing the second argument, instead of the first?
val timesThree = multiply _ (1) // Incorrect Syntax
More importantly, why is there not a direct parallel to multiply(1) _
?
Upvotes: 2
Views: 740
Reputation: 13667
val timesThree = multiply(_: Int)(1)
or
val timesThree = (x: Int) => multiply(x)(1)
Upvotes: 8