The Identity Monad

hymn.types.identity - the identity monad

class hymn.types.identity.Identity(value)

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

the identity monad

bind(f)

the bind operation

f 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().

hymn.types.identity.identity_m

alias of hymn.types.identity.Identity

hymn.types.identity.unit()

alias of Identity.unit()

Hy Specific API

identity-m

alias of Identity

Examples

=> (import [hymn.types.identity [identity-m]])
=> (require [hymn.macros [do-monad-return]])
=> (do-monad-return [a (identity-m.unit 1) b (identity-m.unit 2)] (+ a b))
Identity(3)

Identity monad is comparable as long as what’s wrapped inside are comparable.

=> (import [hymn.types.identity [identity-m]])
=> (> (identity-m.unit 2) (identity-m.unit 1))
True
=> (= (identity-m.unit 42) (identity-m.unit 42))
True