Module

Control.Monad.Rec.Loops

Package
purescript-monad-loops
Repository
mlang/purescript-monad-loops

#whileM Source

whileM :: forall m a. MonadRec m => m Boolean -> m a -> m (Array 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 Array. See whileM' for a generalized Applicative monoidal result.

#whileM' Source

whileM' :: forall m f a. MonadRec m => Applicative f => Monoid (f a) => m Boolean -> 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 Applicative monoidal structure.

#whileM_ Source

whileM_ :: forall m a. MonadRec m => m Boolean -> m a -> m Unit

Execute an action repeatedly as long as the given boolean expression returns true. The condition is evaluated before the loop body. Ignores the results of loop body execution.

#untilM Source

untilM :: forall m a. MonadRec m => m a -> m Boolean -> m (Array a)

Execute an action repeatedly until the condition expression returns true. The condition is evaluated after the loop body. Collects results into an Array.

#untilM' Source

untilM' :: forall m f a. MonadRec m => Applicative f => Semigroup (f a) => m a -> m Boolean -> m (f a)

Execute an action repeatedly until the condition expression returns true. The condition is evaluated after the loop body. Collects results into an arbitrary Applicative semigroupoid structure.

#untilM_ Source

untilM_ :: forall m a. MonadRec m => m a -> m Boolean -> m Unit

Execute an action repeatedly until the condition expression returns true. The condition is evaluated after the loop body. Ignores the results of loop body execution.

#iterateWhile Source

iterateWhile :: forall m a. MonadRec m => (a -> Boolean) -> m a -> m a

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

#iterateUntil Source

iterateUntil :: forall m a. MonadRec m => (a -> Boolean) -> m a -> m a

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

#iterateUntilM Source

iterateUntilM :: forall m a. MonadRec m => (a -> Boolean) -> (a -> m a) -> a -> m a

Yields the result of applying f until p holds.

#whileJust Source

whileJust :: forall m b a. MonadRec m => m (Maybe a) -> (a -> m b) -> m (Array 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 array.

#whileJust' Source

whileJust' :: forall m f b a. MonadRec m => Applicative f => Monoid (f b) => 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.

#whileJust_ Source

whileJust_ :: forall m b a. MonadRec m => m (Maybe a) -> (a -> m b) -> m Unit

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.

#untilJust Source

untilJust :: forall m a. MonadRec m => m (Maybe a) -> m a

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

#unfoldM Source

unfoldM :: forall m a. MonadRec m => m (Maybe a) -> m (Array a)

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

#unfoldM' Source

unfoldM' :: forall m f a. MonadRec m => Applicative f => Monoid (f a) => 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 Applicative Monoid.

#unfoldM_ Source

unfoldM_ :: forall m a. MonadRec m => m (Maybe a) -> m Unit

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

#unfoldrM Source

unfoldrM :: forall m b a. MonadRec m => (a -> m (Maybe (Tuple b a))) -> a -> m (Array b)

#unfoldrM' Source

unfoldrM' :: forall m f b a. MonadRec m => Applicative f => Monoid (f b) => (a -> m (Maybe (Tuple b a))) -> a -> m (f b)

See 'Data.List.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.

#andM Source

andM :: forall m. MonadRec m => List (m Boolean) -> m Boolean

short-circuit 'and' for monadic boolean values.

#orM Source

orM :: forall m. MonadRec m => List (m Boolean) -> m Boolean

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

#anyPM Source

anyPM :: forall a m. MonadRec m => List (a -> m Boolean) -> (a -> m Boolean)

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.

#allPM Source

allPM :: forall m a. MonadRec m => List (a -> m Boolean) -> (a -> m Boolean)

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.

#anyM Source

anyM :: forall m a. MonadRec m => (a -> m Boolean) -> List a -> m Boolean

short-circuit 'any' with a "monadic predicate".

#allM Source

allM :: forall a m. MonadRec m => (a -> m Boolean) -> List a -> m Boolean

short-circuit 'all' with a "monadic predicate".