In the chain documentation you find:
Calling
chainon a wrapped object will cause all future method calls
to return wrapped objects as well. When you’ve finished the
computation, usevalueto retrieve the final value.
So does the chain function create a monad?
No, not a monad, but a comonad! It turns a function that takes a wrapped object and returns a normal value into a function that both takes and returns a wrapped object. As a Haskell type signature that would be:
The type signature of
valueis:These are precisely what you need for a comonad. The first function is usually called
extendand the secondextract.You can think of a comonad as a value with some extra context. And that is of course exactly what
chaindoes.See this Stackoverflow question for more about comonads.