Skip to content

Coal.Monad

Monads extend applicative functors with sequential composition, allowing effectful computations to be chained where each step depends on the result of the previous one.


Monad

trait

Trait that extends Applicative with bind (also known as flat-map), enabling sequential composition of effectful computations.

  • bind : m<a> -> (a -> m<b>) -> m<b>

then_do

then_do sequences two monadic actions, discarding the result of the first and returning the second.

then_do : m<a> -> m<b> -> m<b> with (Monad<m>)then_do : m<a> -> m<b> -> m<b> with (Monad<m>)

and_then

and_then is bind with its arguments flipped: the continuation comes first, making it read like "and then do this with the result".

and_then : (a -> m<b>) -> m<a> -> m<b> with (Monad<m>)and_then : (a -> m<b>) -> m<a> -> m<b> with (Monad<m>)

and_eval

and_eval is then_do with its arguments flipped: the second action is evaluated first, and the first is returned.

and_eval : m<b> -> m<a> -> m<a> with (Monad<m>)and_eval : m<b> -> m<a> -> m<a> with (Monad<m>)

and_return

and_return is and_eval composed with pure: it runs the given monadic action, discarding its result, and returns the given pure value.

and_return : a -> m<b> -> m<a> with (Monad<m>)and_return : a -> m<b> -> m<a> with (Monad<m>)

join

join flattens a nested monadic value by one level, transforming m<m<a>> into m<a>. It is equivalent to bind with the identity function.

join : m<m<a>> -> m<a> with (Monad<m>)join : m<m<a>> -> m<a> with (Monad<m>)