Monad¶
monad.types.monad - The Monad Class.
-
class
monad.types.monad.Monad(value)[source]¶ Bases:
monad.types.applicative.ApplicativeThe Monad Class.
Implements bind operator
>>and inverted bind operator<<as syntactic sugar. It is equivalent to(>>=)and(=<<)in haskell, not to be confused with(>>)and(<<)in haskell.As python treats assignments as statements, there is no way we can overload
>>=as a chainable bind, be it directly overloaded through__irshift__, or derived by python itself through__rshift__.The default implementations of
bind,fmapandjoinare mutual recursive, subclasses should at least either overloadbind, orfmapandjoin, or all of them for better performance.-
bind(function)[source]¶ The bind operation.
functionis a function that maps from the underlying value to a monadic type, something like signaturef :: a -> M ain haskell’s term.The default implementation defines
bindin terms offmapandjoin.
-
fmap(function)[source]¶ The fmap operation.
The default implementation defines
fmapin terms ofbindandunit.
-