flix

0.54.0

Monad

trait Monad[m: Type -> Type] with Applicative[m]Source

A trait for applicatives that support monadic bind (flatMap), i.e., allow to apply a function that takes a normal value and produces a monadic value to a monadic value. That is, the bind mechanism supports extraction of monadic values, or, viewed differently, allows to combine (flatten) nested monadic values (flapMap can be understood as a Functor.map followed by a flatten).

Instances

instance Monad[Chain]Source
instance Monad[DelayList]Source
instance Monad[Identity]Source
instance Monad[List]Source
instance Monad[Nec]Source
instance Monad[Nel]Source
instance Monad[Option]Source
instance Monad[Result[e]]Source
instance Monad[Vector]Source

Signatures

def flatMap(f: a -> m[b] \ ef, x: m[a]): m[b] \ ef with Monad[m] Source

Apply function f to the monadic value x, resulting in a combined monadic value.

Module Definitions

def <=<(f1: b -> m[c] \ ef1, f2: a -> m[b] \ ef2): a -> m[c] \ ef1 + ef2 with Monad[m] Source

<=< is an operator alias for kleisliRight.

def =<<(k: a -> m[b] \ ef, x: m[a]): m[b] \ ef with Monad[m] Source

=<< is an operator alias for flatMap.

def >=>(f1: a -> m[b] \ ef1, f2: b -> m[c] \ ef2): a -> m[c] \ ef1 + ef2 with Monad[m] Source

>=> is an operator alias for kleisliLeft.

def >>=(x: m[a], k: a -> m[b] \ ef): m[b] \ ef with Monad[m] Source

>>= is the operator =<< with its arguments flipped.

>>= is the monadic bind operator.

def flatten(x: m[m[a]]): m[a] with Monad[m] Source

The monadic join operator. Flatten x - a monadic action nested in an outer monadic layer - to a single layer.

E.g. for the Option monad: flatten(Some(Some(1))) becomes Some(1).

def kleisliLeft(f1: a -> m[b] \ ef1, f2: b -> m[c] \ ef2, x: a): m[c] \ ef1 + ef2 with Monad[m] Source

The left-to-right Kleisli composition operator for monads.

Map x with the monadic function f1 and then map its result with the function f2.

def kleisliRight(f1: b -> m[c] \ ef1, f2: a -> m[b] \ ef2, x: a): m[c] \ ef1 + ef2 with Monad[m] Source

The right-to-left Kleisli composition operator for monads.

Map x with the monadic function f2 and then map its result with the function f1.