- What is functional composition?
Functional composition is an operation on functions. It takes two functions, f and g, and creates a third function, C, with the following property for any argument: x, C(x) = f(g(x)).
- Functional composition has a property that is usually associated with mathematical operations. What is it?
Functional composition is not commutative. For example, squaring the increment of a number is not the same as incrementing the square of a number.
- How can you turn an add function with two parameters into two functions with one parameter?
Consider the following function:
auto add = [](const int first, const int second){ return first + second; };
We can turn the preceding function into the following:
auto add = [](const int first){
return [first](const int second){
return first + second;
};
};
- How can you write a C++ function that...