
Functional Python Programming

The common mathematical notation for a composite function looks as follows:
The idea is that we can define a new function,
, that combines two other functions,
and
.
Python's multiple-line definition of a composition function can be done through the following code:
@f_deco def g(x): something
The resulting function can be essentially equivalent to
. The f_deco()
decorator must define and return the composite function by merging an internal definition of f()
with the provided g()
.
The implementation details show that Python actually provides a slightly more complex kind of composition. The structure of a wrapper makes it helpful to think of Python decorator composition as follows:
A decorator applied to some application function,
, will include a wrapper function,
, that has two parts. One portion of the wrapper,
, applies to the arguments of the wrapped function,
, and the other portion,
, applies to the result of the wrapped function.
Here's a more concrete idea, shown...
Change the font size
Change margin width
Change background colour