‹ BACK

Currying example

Consider the following curried function:
def curriedSum(x: Int)(y: Int) = x + y
There is a way to get an actual reference to curriedSum’s “second” function. You can use the placeholder notation to use curriedSum in a partially applied function expression, like this:
scala> val onePlus = curriedSum(1)_
onePlus: (Int) => Int = <function1>
The underscore in curriedSum(1)_ is a placeholder for the second parameter list. The result is a reference to a function that, when invoked, adds one to its sole Int argument and returns the result:
scala> onePlus(2)
res7: Int = 3
Read more: Currying
higher-order functions functions currying

To check your knowledge the following tests are recommended:
Check your scala scala skills.