5.8 Building higher-order functions with callables
We can define higher-order functions as callable classes. This builds on the idea of writing generator functions; we’ll write callables because we need stateful features of Python, like instance variables. In addition to using statements, we can also apply a static configuration when creating the higher-order functions. The Strategy design pattern, in particular, works very nicely to alter the features of callable objects.
What’s important about a callable class definition is that the class object, created by the class
statement, defines a function that emits a function. Commonly, we’ll use a callable object to create a composite function that combines functions into something relatively complex.
To emphasize this, consider the following class:
from collections.abc import Callable
from typing import Any
class NullAware:
def __init__(self, some_func: Callable[[Any]...