12.6 Composing Functions

12.6  Composing Functions

   When we talk about functions in mathematics, we can talk about concepts such as the complement of a function and the composition of functions. We will now see how we can implement these two ideas in Perl. In mathematics, the complement of a function f is usually written as ~f or . The complement of a function f is a function that returns true whenever f returns false, and vice versa. The composition of two functions is usually denoted by the operator °. If f and g are two mathematical functions, their composition f°g is also a function. The result of obtaining the composed function f°g on a parameter x is given as f°g(x)=f(g(x)).
This can be done using the idea of closures that we have discussed earlier.