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
Войдите чтобы поставить Нравится
Войдите чтобы прокомментировать