13.3 Functors – making everything a function
The idea of a functor is a functional representation of a piece of simple data. A functor version of the number 3.14 is a function of zero arguments that returns this value. Consider the following example:
>>> pi = lambda: 3.14
>>> pi()
3.14
We created a zero-argument lambda object that returns a Python float object.
When we apply a curried function to a functor, we’re creating a new curried functor. This generalizes the idea of applying a function to an argument to get a value by using functions to represent the arguments, the values, and the functions themselves.
Once everything in our program is a function, then all processing becomes a variation on the theme of functional composition. To recover the underlying Python object, we can use the value
attribute of a functor object to get a Python-friendly, simple type that we can use in uncurried code.
Since this kind of programming is based on...