Safe Haskell | None |
---|

Control flow and monadic utilities.

- class Bifunctor p where
- while :: Monad.Monad m => m Bool -> m a -> m [a]
- while_ :: Monad.Monad m => m Bool -> m a -> m ()
- mconcatMap :: Monoid b => (a -> b) -> [a] -> b
- concatMapM :: (Monad.Monad m, Monoid b) => (a -> m b) -> [a] -> m b
- justm :: Monad.Monad m => m (Maybe a) -> (a -> m (Maybe b)) -> m (Maybe b)
- rightm :: Monad.Monad m => m (Either err a) -> (a -> m (Either err b)) -> m (Either err b)
- firstJust :: Monad.Monad m => m (Maybe a) -> m (Maybe a) -> m (Maybe a)
- firstJusts :: Monad.Monad m => [m (Maybe a)] -> m (Maybe a)
- justErr :: err -> Maybe a -> Either err a
- tryJust :: MonadError e m => e -> Maybe a -> m a
- tryRight :: MonadError e m => Either e a -> m a
- module Control.Monad.Extra
- module Util.CallStack

# Documentation

class Bifunctor p where Source #

This is like the hackage bifunctor package, but with no extra dependencies, and no clowns.

while :: Monad.Monad m => m Bool -> m a -> m [a] Source #

while_ :: Monad.Monad m => m Bool -> m a -> m () Source #

mconcatMap :: Monoid b => (a -> b) -> [a] -> b Source #

This is `foldMap`

specialized to lists.

concatMapM :: (Monad.Monad m, Monoid b) => (a -> m b) -> [a] -> m b Source #

This is actually a mconcatMapM.

A further generalized version would be:

foldMapA :: (Applicative f, Traversable t, Monoid m) => (a -> f m) -> t a -> f m foldMapA f = fmap Foldable.fold . traverse f

justm :: Monad.Monad m => m (Maybe a) -> (a -> m (Maybe b)) -> m (Maybe b) Source #

Run the second action only if the first action returns Just.

This is like MaybeT, but using MaybeT itself required lots of annoying explicit lifting.

rightm :: Monad.Monad m => m (Either err a) -> (a -> m (Either err b)) -> m (Either err b) Source #

The Either equivalent of `justm`

. EitherT solves the same problem, but
requires a runEitherT and lots of hoistEithers.

firstJust :: Monad.Monad m => m (Maybe a) -> m (Maybe a) -> m (Maybe a) Source #

Return the first action to return Just.

firstJusts :: Monad.Monad m => [m (Maybe a)] -> m (Maybe a) Source #

`firstJust`

applied to a list.

# errors

tryJust :: MonadError e m => e -> Maybe a -> m a Source #

I usually call this `require`

.

tryRight :: MonadError e m => Either e a -> m a Source #

I usually call this `require_right`

.

module Control.Monad.Extra

module Util.CallStack