5.6 Overview of writing higher-order functions
We’ll look at designing our own higher-order functions. We’ll summarize some of the process before diving into some more complex kinds of design patterns. We’ll start by looking at common data transformations, such as the following:
Wrap objects to create more complex objects
Unwrap complex objects into their components
Flatten a structure
Structure a flat sequence
These patterns can help to visualize ways higher-order functions can be designed in Python.
It can also help to recall that a Callable
class definition is a function that returns a callable object. We’ll look at this as a way to write flexible functions into which configuration parameters can be injected.
We’ll defer deeper consideration of decorators until Chapter 12, Decorator Design Techniques. A decorator is also a higher-order function, but it consumes one function and returns another, making it more complex than the examples in this...