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:
Filter|filter- if your type supportsMonad<F>andMonoidK<F>you get free filtering andWhereLINQ extensionChoose|choose- if your type supportsMonad<F>andMonoidK<F>thenChoosedoes filtering and mappingOneOf|oneOf- takes a collection ofK<F, A>structures, returns the first one to succeed.Some|some- evaluates aK<F, A>structure repeatedly, collecting theAvalues, until it fails (at least one must succeed). Returns theK<F, Seq<A>>Many|many- evaluates aK<F, A>structure repeatedly, collecting theAvalues, until it fails. Returns theK<F, Seq<A>>guard- conditional failure
Some of these you might recognise from the Parsec library. This completely generalises the concept of alternative
structure coalescing.
Contents
- MonoidK <M>
- MonoidKExtensions
- Filter <M, A> (this K<M, A> ma, Func<A, bool> predicate)
- Where <M, A> (this K<M, A> ma, Func<A, bool> predicate)
- Choose <M, A, B> (this K<M, A> ma, Func<A, Option<B>> selector)
- MonoidK
- empty <F, A> ()
- combine <F, A> (K<F, A> ma, K<F, A> mb)
- combine <M, A> (K<M, A> mx, K<M, A> my, K<M, A> mz, params K<M, A>[] xs)
- combine <M, A> (IEnumerable<K<M, A>> xs)
- combine <M, A> (Seq<K<M, A>> xs)
- filter <M, A> (K<M, A> ma, Func<A, bool> predicate)
- choose <M, A, B> (K<M, A> ma, Func<A, Option<B>> selector)
- guard <F> (bool flag)
interface MonoidK <M> Source #
A monoid for higher-kinds
Parameters
| type | M | Higher kind |
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 #
Results in Empty if the predicate results in false
A monoid on higher-kinds
Methods
method K<F, A> combine <F, A> (K<F, A> ma, K<F, A> mb) Source #
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 #
Fold a list using the monoid.
method K<M, A> combine <M, A> (IEnumerable<K<M, A>> xs) Source #
Fold a list using the monoid.
method K<M, A> combine <M, A> (Seq<K<M, A>> xs) Source #
Fold a list using the monoid.
method K<M, A> filter <M, A> (K<M, A> ma, Func<A, bool> predicate) Source #
Results in Empty if the predicate results in false