
Functional Python Programming
By :

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 the form is as follows:
@f def g(x): something
This is vaguely equivalent to . The equivalence isn't very precise because the
@f
decorator isn't the same as the mathematical abstraction of composing and
. For the purposes of discussing function composition, we'll ignore the implementation disconnect between the abstraction of
and the
@f
decorator.
Because decorators wrap another function, Python offers a slightly more generalized composition. We can think of Python design as follows:
A decorator applied to some application function, , will include a wrapper function. One portion of the wrapper,
, applies before the wrapped function and the other portion,
, applies after the wrapped function.
The Wrapper()
function often looks as follows:
@wraps(argument_function) def something_wrapper...
Change the font size
Change margin width
Change background colour