ganeti

Safe HaskellSafe

Ganeti.Utils.Monad

Contents

Description

Utility functions for MonadPlus operations

Synopsis
  • mretryN :: MonadPlus m => Int -> (Int -> m a) -> m a
  • retryMaybeN :: Monad m => Int -> (Int -> MaybeT m a) -> m (Maybe a)
  • retryErrorN :: MonadError e m => Int -> (Int -> m a) -> m a
  • anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool
  • allM :: Monad m => (a -> m Bool) -> [a] -> m Bool
  • orM :: Monad m => [m Bool] -> m Bool
  • unfoldrM :: Monad m => (a -> m (Maybe (b, a))) -> a -> m [b]
  • unfoldrM' :: (Monad m, MonadPlus f) => (a -> m (Maybe (b, a))) -> a -> m (f b)

Documentation

mretryN :: MonadPlus m => Int -> (Int -> m a) -> m a Source #

Retries the given action up to n times. The action signals failure by mzero.

retryMaybeN :: Monad m => Int -> (Int -> MaybeT m a) -> m (Maybe a) Source #

Retries the given action up to n times. The action signals failure by mzero.

retryErrorN :: MonadError e m => Int -> (Int -> m a) -> m a Source #

Retries the given action up to n times until it succeeds. If all actions fail, the error of the last one is returned. The action is always run at least once, even if n is less than 1.

From monad-loops (until we can / want to depend on it):

anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool Source #

Short-circuit any with a monadic predicate.

allM :: Monad m => (a -> m Bool) -> [a] -> m Bool Source #

Short-circuit all with a monadic predicate.

orM :: Monad m => [m Bool] -> m Bool Source #

Short-circuit or for values of type Monad m => m Bool

unfoldrM :: Monad m => (a -> m (Maybe (b, a))) -> a -> m [b] Source #

See unfoldr. This is a monad-friendly version of that.

unfoldrM' :: (Monad m, MonadPlus f) => (a -> m (Maybe (b, a))) -> a -> m (f b) Source #

See unfoldr. This is a monad-friendly version of that, with a twist. Rather than returning a list, it returns any MonadPlus type of your choice.