-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Haskell98 partial maps and filters over MonadPlus. -- -- Filtering and folding over arbitrary MonadPlus instances. This -- package generalizes many common stream operations such as -- filter, catMaybes etc. @package monadplus @version 1.4 -- | Partial maps and filters over MonadPlus instances. The basic -- idea here is that the monad interface together with the monoidal -- structure of MonadPlus is enough to implement partial maps and -- filters (i.e. mmapMaybe and mfilter). -- -- This is especially useful for sequential structures such as event -- lists, tracks etc. -- -- Inspired by the following blog post: -- --
module Control.Monad.Plus -- | This generalizes the list-based concat function. msum :: MonadPlus m => [m a] -> m a -- | This generalizes the list-based concat function. msum' :: (MonadPlus m, Foldable t) => t (m a) -> m a -- | Fold a value into an arbitrary MonadPlus type. -- -- This function generalizes the toList function. mfold :: (MonadPlus m, Foldable t) => t a -> m a -- | Translate a list to an arbitrary MonadPlus type. -- -- This function generalizes the listToMaybe function. mfromList :: MonadPlus m => [a] -> m a -- | Translate maybe to an arbitrary MonadPlus type. -- -- This function generalizes the maybeToList function. mfromMaybe :: MonadPlus m => Maybe a -> m a -- | The partition function takes a predicate a list and returns the -- pair of lists of elements which do and do not satisfy the predicate, -- respectively; i.e., -- ---- partition p xs == (filter p xs, filter (not . p) xs) ---- -- This function generalizes the partition function. mpartition :: MonadPlus m => (a -> Bool) -> m a -> (m a, m a) -- | Join list elements together. -- -- This function generalizes the catMaybes function. mscatter :: MonadPlus m => m [b] -> m b -- | Join foldable elements together. -- -- This function generalizes the catMaybes function. mscatter' :: (MonadPlus m, Foldable t) => m (t b) -> m b -- | Pass through Just elements. -- -- This function generalizes the catMaybes function. mcatMaybes :: MonadPlus m => m (Maybe a) -> m a -- | Pass through Left elements. -- -- This function generalizes the lefts function. mlefts :: MonadPlus m => m (Either a b) -> m a -- | Pass through Right elements. -- -- This function generalizes the rights function. mrights :: MonadPlus m => m (Either a b) -> m b -- | Separate Left and Right elements. -- -- This function generalizes the partitionEithers function. mpartitionEithers :: MonadPlus m => m (Either a b) -> (m a, m b) -- | Modify or discard a value. -- -- This function generalizes the mapMaybe function. mmapMaybe :: MonadPlus m => (a -> Maybe b) -> m a -> m b -- | Modify, discard or spawn values. -- -- This function generalizes the concatMap function. mconcatMap :: MonadPlus m => (a -> [b]) -> m a -> m b -- | Wrapper for partial functions with MonadPlus instance. newtype Partial a b Partial :: (a -> Maybe b) -> Partial a b getPartial :: Partial a b -> a -> Maybe b -- | Convert a predicate to a partial function. partial :: (a -> Bool) -> a -> Maybe a -- | Convert a partial function to a predicate. predicate :: (a -> Maybe a) -> a -> Bool -- | Convert a total function to a partial function. always :: (a -> b) -> a -> Maybe b -- | Make a partial function that always rejects its input. never :: a -> Maybe c instance Monoid (Partial a b) instance Alternative (Partial r) instance Applicative (Partial r) instance MonadPlus (Partial r) instance Monad (Partial r) instance Functor (Partial r) -- | Partial maps and filters over Alternative instances. -- -- This is considerably weaker than MonadPlus, as we have no -- possibility of removing intermediate structure, as in -- mcatMaybes. module Control.Applicative.Alternative -- | The sum of a collection of actions, generalizing concat. asum :: (Foldable t, Alternative f) => t (f a) -> f a -- | Fold a value into an arbitrary MonadPlus type. -- -- This function generalizes the toList function. afold :: (Alternative f, Foldable t) => t a -> f a -- | This function generalizes the listToMaybe function. afromList :: Alternative f => [a] -> f a -- | Translate maybe to an arbitrary Alternative type. -- -- This function generalizes the maybeToList function. afromMaybe :: Alternative f => Maybe a -> f a