monadplus-1.1: To be written.

Safe HaskellSafe-Inferred

Control.Monad.Plus

Synopsis

Documentation

class Monad m => MonadPlus m where

Monads that also support choice and failure.

Methods

mzero :: m a

the identity of mplus. It should also satisfy the equations

 mzero >>= f  =  mzero
 v >> mzero   =  mzero

mplus :: m a -> m a -> m a

an associative operation

Instances

msum :: MonadPlus m => [m a] -> m a

This generalizes the list-based concat function.

mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a

Direct MonadPlus equivalent of filter filter = (mfilter:: (a -> Bool) -> [a] -> [a] applicable to any MonadPlus, for example mfilter odd (Just 1) == Just 1 mfilter odd (Just 2) == Nothing

mremove :: MonadPlus m => (a -> Bool) -> m a -> m aSource

Generalizes the remove function.

mpartition :: MonadPlus m => (a -> Bool) -> m a -> (m a, m a)Source

Generalizes the partition function.

mfromMaybe :: MonadPlus m => Maybe a -> m aSource

Translate maybe to an arbitrary MonadPlus type. Generalizes the maybeToList function.

mcatMaybes :: MonadPlus m => m (Maybe a) -> m aSource

Pass through Just occurrences. Generalizes the catMaybes function.

mmapMaybe :: MonadPlus m => (a -> Maybe b) -> m a -> m bSource

Modify or discard a value. Generalizes the mapMaybe function.