Self-returning Function
Previous: More Hemingway
Yesterday I gave a solution to the problem of creating a chainable function by implementing a class with a method that returned the instance. Today I implemented the solution using a function that returns itself, more in line with the intent of Croll’s exercise.
Working in Python, I defined a prototype function called sayIt
that was not chainable, and then defined a class that used a similar method to make it chainable.
I decided to change my prototype so that it would invoke itself in its return statement, as suggested by the solutions Croll provides.
Here are the implementations, both as a function with global and as a class:
And here’s its usage in the Python 3 interpreter:
Previous: More Hemingway