One big part of functional programming as a concept is to use functions in the same way that we use any other type—as values, parameters, returns, and so on. One thing that we can do with other types is to take them as construction blocks to build other types; the same concept can be applied to functions.
Function composition is a technique to build functions using existing functions; similar to Unix pipes or channel pipelines, the result value of a function is used as a parameter for the next one.
In Arrow, function composition comes as a set of the infix
extension functions:
Function | Description |
| Takes the result of invoking the right-hand function as the parameter for the left-hand function. |
| Takes the result of invoking the left-hand function as the parameter for the right-hand function. |
| Is an alias for |
Let's compose some functions:
import arrow.syntax.function.andThen import arrow.syntax.function.compose import arrow.syntax.function...