Currying is the technique of translating the evaluation of a function that takes multiple arguments (or a tuple of arguments) into evaluating a sequence of functions, each with a single argument.
For example a normal function:
// (Int, int) -> Int
fun sum(a: Int, b: Int): Int = a + b
sum(2, 2) //4
could be rewritten like this:
//Int -> (Int -> Int)
fun sum(a: Int): (Int) -> Int {
return { b: Int -> a + b }
}
val twoPlus = sum(2)
twoPlus(2) // 4
sum(2)(2) // 4
This is a two-arity function #5.
Conclusion
Currying transform a function that takes multiple arguments and returned it as a chain of functions
Currying is the technique of translating the evaluation of a function that takes multiple arguments (or a tuple of arguments) into evaluating a sequence of functions, each with a single argument.
For example a normal function:
could be rewritten like this:
This is a two-arity function #5.
Conclusion
Currying transform a function that takes multiple arguments and returned it as a chain of functions
Resources
Curriying