"Pure" Objects
I'm starting to find it useful to extend the notion of "pure" functions to objects. A "pure" object is one where constructing it and then any sequence of method calls on it will produce an equivalent instance of the object if repeated with the same arguments. More formally, it is an object whose constructor and methods would be pure functions if not for their use of instance state. As if the instance state is implicitly made part of the parameters and returns of the constructor and methods, like with a state monad.
We might be tempted to restrict "pure" only to objects which do not change their own instance state, but I think in most cases that would make the definition less useful - functions can change their inner state while they execute and still be considered "pure". Instance variables in an object are analogous to local variables in a function in many ways. A sequence of method calls in a "pure" object is a lot like a "pure" function which can be paused and resumed: like a generator which yields intermediate outputs, a curried function which does work before taking its next argument, a coroutine which is still purely a function of its inputs and outputs, or like several "pure" functions using the same state monad.












