Function composition
If you have two functions and , then you can define a third function:
It basically means: First apply the function on the right. Then use that result and apply the left function. Of course, you can use more than two and repeat that process.
In code, you can either explicitly call the first function and then the second or you can create a new function using something like lambda expressions.
Code:
This version applies the argument directly. In languages, that don't support passing functions as parameters, you might need to explicitly write functions for all combinations or use some other mechanism
Here we create a new function that is the composition of and and can be called as .