September 2018
Intermediate to advanced
398 pages
9h 43m
English
A curried function is a function that takes one parameter and returns another function that takes one parameter. You can convert a function value into a curried function value by calling the .curried method, as shown in the following code:
val multiplyCurried = multiplyVal.curried// multiplyCurried: Int => (Int => Int) = ...
The call to .curried transforms the function value's type from (Int, Int) => Int to Int => (Int => Int). The multiplyVal takes two integers as parameters and returns an integer. The multiplyCurried takes one Int and returns a function that takes Int and returns Int. The two function values have exactly the same functionality—the difference lies in the way we call them, as shown in the following code:
multiplyVal( ...
Read now
Unlock full access