LanguageExt.Core

LanguageExt.Core Traits MonoidK

MonoidK<F> inherits SemigroupK<F>. The way to think of MonoidK<F> is a monoid for higher-kinds (K<F, A> types, rather than A types).

What that means is that any type that implements the MonoidK<F> trait gains an Empty() (a 'zero'/identity element ) value as well as the ability to Combine two K<F, A> structures together into one. Many implementations of MonoidK<F> use Combine to catch errors and propagate. So, if the first K<F, A> argument to Combine fails, it simply returns the second argument. If it succeeds, then the result of the first is returned. This works a bit like null propagation with the ?? operator. And while this isn't always how MonoidK is implemented, it's useful to know.

The MonoidK<F> trait combines with Applicative<F> and Monad<F> traits to provide the following default functionality:

Some of these you might recognise from the Parsec library. This completely generalises the concept of alternative structure coalescing.

Contents

interface MonoidK <M> Source #

where M : MonoidK<M>

A monoid for higher-kindS

Parameters

type M

Higher kind

Methods

method K<M, A> Empty <A> () Source #

class MonoidKExtensions Source #

A monoid on applicative functors

Parameters

type F

Applicative functor

Methods

method K<M, A> Filter <M, A> (this K<M, A> ma, Func<A, bool> predicate) Source #

where M : MonoidK<M>, Monad<M>

Results in Empty if the predicate results in false

method K<M, A> Where <M, A> (this K<M, A> ma, Func<A, bool> predicate) Source #

where M : MonoidK<M>, Monad<M>

Results in Empty if the predicate results in false

method K<M, B> Choose <M, A, B> (this K<M, A> ma, Func<A, Option<B>> selector) Source #

where M : MonoidK<M>, Monad<M>

Chooses whether an element of the structure should be propagated through and if so maps the resulting value at the same time.

class MonoidK Source #

A monoid on higher-kinds

Methods

method K<F, A> empty <F, A> () Source #

where F : MonoidK<F>

Identity

Parameters

type A
returns

method K<F, A> combine <F, A> (K<F, A> ma, K<F, A> mb) Source #

where F : MonoidK<F>

Associative binary operator

method K<M, A> combine <M, A> (K<M, A> mx, K<M, A> my, K<M, A> mz, params K<M, A>[] xs) Source #

where M : MonoidK<M>

Fold a list using the monoid.

method K<M, A> combine <M, A> (IEnumerable<K<M, A>> xs) Source #

where M : MonoidK<M>

Fold a list using the monoid.

method K<M, A> combine <M, A> (Seq<K<M, A>> xs) Source #

where M : MonoidK<M>

Fold a list using the monoid.

method K<M, A> filter <M, A> (K<M, A> ma, Func<A, bool> predicate) Source #

where M : MonoidK<M>, Monad<M>

Results in Empty if the predicate results in false

method K<M, B> choose <M, A, B> (K<M, A> ma, Func<A, Option<B>> selector) Source #

where M : MonoidK<M>, Monad<M>

Chooses whether an element of the structure should be propagated through and if so maps the resulting value at the same time.

method K<F, Unit> guard <F> (bool flag) Source #

where F : MonoidK<F>, Applicative<F>

Conditional failure of Alternative computations. Defined by

guard(true)  = Applicative.pure
guard(false) = Alternative.empty

Parameters

type F
param flag
returns