arrow-mtl / arrow.mtl.typeclasses / MonadFilter

MonadFilter

interface MonadFilter<F> : Monad<F>, FunctorFilter<F>

Functions

bindingFilter open fun <B> bindingFilter(c: suspend MonadFilterContinuation<F, *>.() -> B): Kind<F, B>
Entry point for monad bindings which enables for comprehension. The underlying impl is based on coroutines. A coroutine is initiated and inside MonadContinuation suspended yielding to flatMap. Once all the flatMap binds are completed the underlying monad is returned from the act of executing the coroutine
empty abstract fun <A> empty(): Kind<F, A>
mapFilter open fun <A, B> Kind<F, A>.mapFilter(f: (A) -> Option<B>): Kind<F, B>
A combined map and filter. Filtering is handled via Option instead of Boolean such that the output type B can be different than the input type A.

Inherited Functions

collect open fun <A, B> Kind<F, A>.collect(f: PartialFunction<A, B>): Kind<F, B>
Similar to mapFilter but uses a partial function instead of a function that returns an Option.
filter open fun <A> Kind<F, A>.filter(f: (A) -> Boolean): Kind<F, A>
Apply a filter to a structure such that the output structure contains all A elements in the input structure that satisfy the predicate f but none that don’t.
flattenOption open fun <A> Kind<F, Option<A>>.flattenOption(): Kind<F, A>
“Flatten” out a structure by collapsing Options.

Inheritors

ListKMonadFilter interface ListKMonadFilter : MonadFilter<ForListK>
MonadCombine interface MonadCombine<F> : MonadFilter<F>, Alternative<F>
OptionMonadFilter interface OptionMonadFilter : MonadFilter<ForOption>
SequenceKMonadFilter interface SequenceKMonadFilter : MonadFilter<ForSequenceK>
WriterTMonadFilter interface WriterTMonadFilter<F, W> : MonadFilter<WriterTPartialOf<F, W>>, WriterTMonad<F, W>

Type Class Hierarchy