HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulemonad-loops-0.4.3Haskell98

Control.Monad.Loops

A collection of loop operators for use in monads (mostly in stateful ones).

There is a general naming pattern for many of these: Functions with names ending in _ discard the results of the loop body as in the standard Prelude mapM functions.

Functions with names ending in ' collect their results into MonadPlus containers. Note that any short-circuit effect that those types' MonadPlus instances may provide in a lazy context (such as the instance for Maybe) will _not_ cause execution to short-circuit in these loops.

Functions with names ending in neither of those will generally return just plain old lists.

  • 47 values
  • Packagemonad-loops-0.4.3
  • Exports47
  • LanguageHaskell98
  • LicenceLicenseRef-PublicDomain
  • SourceLoops.hs
valueforkMapM :: (a -> IO b) -> [a] -> IO [Either SomeException b]
#

Like mapM, but run all the actions in parallel threads, collecting up the results and returning them all. Does not return until all actions finish.

valueforkMapM__ :: (a -> IO b) -> [a] -> IO ()
#

like forkMapM_ but not even bothering to track success or failure of the child threads. Still waits for them all though.

valuewhileM :: Monad m => m Bool -> m a -> m [a]
#

Execute an action repeatedly as long as the given boolean expression returns True. The condition is evaluated before the loop body. Collects the results into a list.

valuewhileM' :: (Monad m, MonadPlus f) => m Bool -> m a -> m (f a)
#

Execute an action repeatedly as long as the given boolean expression returns True. The condition is evaluated before the loop body. Collects the results into an arbitrary MonadPlus value.

valuewhileM_ :: Monad m => m Bool -> m a -> m ()
#

Execute an action repeatedly as long as the given boolean expression returns True. The condition is evaluated before the loop body. Discards results.

valueiterateWhile :: Monad m => (a -> Bool) -> m a -> m a
#

Execute an action repeatedly until its result fails to satisfy a predicate, and return that result (discarding all others).

valueiterateUntil :: Monad m => (a -> Bool) -> m a -> m a
#

Execute an action repeatedly until its result satisfies a predicate, and return that result (discarding all others).

valueiterateM_ :: Monad m => (a -> m a) -> a -> m b
#

Execute an action forever, feeding the result of each execution as the input to the next.

valueuntilM :: Monad m => m a -> m Bool -> m [a]
#

Execute an action repeatedly until the condition expression returns True. The condition is evaluated after the loop body. Collects results into a list. Parameters are arranged for infix usage. eg. do {...} untilM_ ...

valueuntilM' :: (Monad m, MonadPlus f) => m a -> m Bool -> m (f a)
#

Execute an action repeatedly until the condition expression returns True. The condition is evaluated after the loop body. Collects results into a MonadPlus value. Parameters are arranged for infix usage. eg. do {...} untilM_ ...

valueuntilM_ :: Monad m => m a -> m Bool -> m ()
#

Execute an action repeatedly until the condition expression returns True. The condition is evaluated after the loop body. Discards results. Parameters are arranged for infix usage. eg. do {...} untilM_ ...

valueiterateUntilM :: Monad m => (a -> Bool) -> (a -> m a) -> a -> m a
#

Analogue of (until) Yields the result of applying f until p holds.

valuewhileJust :: Monad m => m (Maybe a) -> (a -> m b) -> m [b]
#

As long as the supplied Maybe expression returns "Just _", the loop body will be called and passed the value contained in the Just. Results are collected into a list.

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

As long as the supplied Maybe expression returns "Just _", the loop body will be called and passed the value contained in the Just. Results are collected into an arbitrary MonadPlus container.

valuewhileJust_ :: Monad m => m (Maybe a) -> (a -> m b) -> m ()
#

As long as the supplied Maybe expression returns "Just _", the loop body will be called and passed the value contained in the Just. Results are discarded.

valueuntilJust :: Monad m => m (Maybe a) -> m a
#

Run the supplied Maybe computation repeatedly until it returns a value. Returns that value.

valueunfoldM :: Monad m => m (Maybe a) -> m [a]
#

The supplied Maybe expression will be repeatedly called until it returns Nothing. All values returned are collected into a list.

valueunfoldM' :: (Monad m, MonadPlus f) => m (Maybe a) -> m (f a)
#

The supplied Maybe expression will be repeatedly called until it returns Nothing. All values returned are collected into an arbitrary MonadPlus thing.

valueunfoldM_ :: Monad m => m (Maybe a) -> m ()
#

The supplied Maybe expression will be repeatedly called until it returns Nothing. All values returned are discarded.

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

Repeatedly evaluates the second argument until the value satisfies the given predicate, and returns a list of all values that satisfied the predicate. Discards the final one (which failed the predicate).

valueunfoldWhileM' :: (Monad m, MonadPlus f) => (a -> Bool) -> m a -> m (f a)
#

Repeatedly evaluates the second argument until the value satisfies the given predicate, and returns a MonadPlus collection of all values that satisfied the predicate. Discards the final one (which failed the predicate).

valueunfoldrM'
  1. :: (Monad m, MonadPlus f)
  2. => a -> m (Maybe (b, a))
  3. -> a
  4. -> m (f b)
#

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.

valueconcatM :: Monad m => [a -> m a] -> a -> m a
#

Compose a list of monadic actions into one action. Composes using (>=>) - that is, the output of each action is fed to the input of the one after it in the list.

valueorM :: Monad m => [m Bool] -> m Bool
#

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

valueanyPM :: Monad m => [a -> m Bool] -> a -> m Bool
#

short-circuit any with a list of "monadic predicates". Tests the value presented against each predicate in turn until one passes, then returns True without any further processing. If none passes, returns False.

valueallPM :: Monad m => [a -> m Bool] -> a -> m Bool
#

short-circuit all with a list of "monadic predicates". Tests the value presented against each predicate in turn until one fails, then returns False. if none fail, returns True.

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

short-circuit any with a "monadic predicate".

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

short-circuit all with a "monadic predicate".

valuefirstM :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a)
#

return the first value from a list, if any, satisfying the given predicate.