ā All posts
Scala / Partial Applied Function
Posted On 12.24.2021
Like currying, if a function takes some arguments and we invoke that function without all of the arguments, a new function will be created so we can call it with the remaining functions later on.
In Scala, it is called Partial Applied Function, and we can call it with the place holder like this:
def sum(a: Int, b: Int): Int = a + b
val add5 = sum(5, _)
def main(args: Array[String]): Unit =
print(add5(10))
In JavaScript, it is equivalent to bind
method:
const sum = (a, b) => a + b;
const add5 = sum.bind(null, 5);
debug(add5(10));