Functions currying
Currying is a common technique in functional programming. It allows transforming a given function that takes multiple arguments into a sequence of functions, each having a single argument. Each of the resulting functions handles one argument of the original (uncurried) function and returns another function.
In this recipe, we are going to implement an automatic currying mechanism that could be applied to any function taking three parameters.
Getting ready
To understand the concept of function currying, let's consider the following example of a function handling three parameters:
fun foo(a: A, b: B, c: C): D
Its curried form would look like this:
fun carriedFoo(a: A): (B) -> (C) -> D
In other words, the curried form of the foo
function would take a single argument of the A
type and return another function of the following type: (B) -> (C) -> D
. The returned function is responsible for handling the second argument of the original function and...