The Identity Monad

monad.types.identity - The Identity Monad.

class monad.types.identity.Identity(value)[source]

Bases: monad.types.monad.Monad, monad.mixins.ContextManager, monad.mixins.Ord

The Identity Monad.

>>> Identity(42)
Identity(42)
>>> Identity([1, 2, 3])
Identity([1, 2, 3])

Comparison with ==, as long as what’s wrapped inside are comparable.

>>> Identity(42) == Identity(42)
True
>>> Identity(42) == Identity(24)
False
bind(function)[source]

The bind operation.

function is a function that maps from the underlying value to a monadic type, something like signature f :: a -> M a in haskell’s term.

The default implementation defines bind in terms of fmap and join.