Currying
Partial application.
What is currying?
Currying transforms a function of several arguments into a chain of functions, each taking one argument. In Scala this is written with multiple parameter lists.
object Main {
def add(a: Int)(b: Int): Int = a + b
def main(args: Array[String]): Unit = {
println(add(3)(4))
}
}Multiple parameter lists
A curried method has several parameter lists: def f(a: Int)(b: Int). You call it by supplying each list in turn: f(1)(2).
object Main {
def combine(prefix: String)(value: Int): String = s"$prefix$value"
def main(args: Array[String]): Unit = {
println(combine("id-")(42))
}
}