john_science
john_science

Reputation: 6541

Order of Arguments in Curried Scala Functions

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

Answers (1)

wingedsubmariner
wingedsubmariner

Reputation: 13667

val timesThree = multiply(_: Int)(1)

or

val timesThree = (x: Int) => multiply(x)(1)

Upvotes: 8

Related Questions