IfElse-0.85.0.0.1: Anaphoric and miscellaneous useful control-flow

Safe Haskell | None
Language | Haskell98

Control.Monad.IfElse

Description

Library for control flow inside of monads with anaphoric variants on if and when and a C-like "switch" function.

Information:

`Author`
  Jeff Heard
`Copyright`
  2008 Jeff Heard
`License`
  BSD
`Version`
  1.0
`Status`
  Alpha

Synopsis

- whenM :: Monad m => m Bool -> m () -> m ()
- cond :: Monad m => [(Bool, m ())] -> m ()
- condM :: Monad m => [(m Bool, m ())] -> m ()
- awhen :: Monad m => Maybe a -> (a -> m ()) -> m ()
- awhenM :: Monad m => m (Maybe a) -> (a -> m ()) -> m ()
- acond :: Monad m => [(Maybe a, a -> m ())] -> m ()
- aif :: Monad m => Maybe a -> (a -> m b) -> m b -> m b
- aifM :: Monad m => m (Maybe a) -> (a -> m b) -> m b -> m b
- unlessM :: Monad m => m Bool -> m () -> m ()
- ncond :: Monad m => [(Bool, m ())] -> m ()
- ncondM :: Monad m => [(m Bool, m ())] -> m ()
- (&&^) :: Monad m => m Bool -> m Bool -> m Bool
- (||^) :: Monad m => m Bool -> m Bool -> m Bool
- (>>?) :: Applicative f => Bool -> f () -> f ()
- (>>!) :: Applicative f => Bool -> f () -> f ()
- (>>=>>!) :: Monad m => m Bool -> m () -> m ()
- (>>=?) :: Monad m => Maybe a -> (a -> m ()) -> m ()
- (>>=>>?) :: Monad m => m Bool -> m () -> m ()
- (>>=>>=?) :: Monad m => m (Maybe a) -> (a -> m ()) -> m ()
- whileM :: Monad m => m Bool -> m () -> m ()
- untilM :: Monad m => m Bool -> m () -> m ()
- return' :: Monad m => a -> m a
- returning :: Monad m => (a -> m b) -> a -> m a
- maybeMP :: MonadPlus m => Maybe a -> m a

# Documentation

whenM :: Monad m => m Bool -> m () -> m () Source #

A if with no else for unit returning thunks. Returns the value of the test.

cond :: Monad m => [(Bool, m ())] -> m () Source #

Like a switch statement, and less cluttered than if else if

    cond [ (t1,a1), (t2,a2), ... ]

condM :: Monad m => [(m Bool, m ())] -> m () Source #

Like a switch statement, and less cluttered than if else if

    condM [ (t1,a1), (t2,a2), ... ]

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

Chainable anaphoric when. Takes a maybe value.

if the value is Just x then execute `action x` , then return `True` . otherwise return `False` .

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

Chainable anaphoric whenM.

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

Anaphoric when-else chain. Like a switch statement, but less cluttered

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

Anaphoric if.

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

Anaphoric if where the test is in Monad m.

unlessM :: Monad m => m Bool -> m () -> m () Source #

Contrapositive of whenM, if not x then do y

ncond :: Monad m => [(Bool, m ())] -> m () Source #

unless-else chain.

ncondM :: Monad m => [(m Bool, m ())] -> m () Source #

monadic unless-else chain

(&&^) :: Monad m => m Bool -> m Bool -> m Bool Source #

IO lifted `&&`

(||^) :: Monad m => m Bool -> m Bool -> m Bool Source #

IO lifted `||`

(>>?) :: Applicative f => Bool -> f () -> f () infixl 1 Source #

Conditionally do the right action based on the truth value of the left expression

(>>!) :: Applicative f => Bool -> f () -> f () infixl 1 Source #

unless the left side is true, perform the right action

(>>=>>!) :: Monad m => m Bool -> m () -> m () infixl 1 Source #

unless the (monadic) left side is true, perform the right action

(>>=?) :: Monad m => Maybe a -> (a -> m ()) -> m () infixl 1 Source #

Bind the result of the last expression in an anaphoric when.

(>>=>>?) :: Monad m => m Bool -> m () -> m () infixl 1 Source #

composition of `>>=` and `>>?`

(>>=>>=?) :: Monad m => m (Maybe a) -> (a -> m ()) -> m () infixl 1 Source #

composition of `>>=` and `>>=?`

whileM :: Monad m => m Bool -> m () -> m () Source #

Execute a monadic action so long as a monadic boolean returns true.

untilM :: Monad m => m Bool -> m () -> m () Source #

Negation of `whileM`: execute an action so long as the boolean returns false.

return' :: Monad m => a -> m a Source #

Strict version of `return` because usually we don't need that extra thunk.

returning :: Monad m => (a -> m b) -> a -> m a infixr 8 Source #

Take an action and make it into a side-effecting `return`. Because I seem to keep running into `m ()` and the like.

maybeMP :: MonadPlus m => Maybe a -> m a Source #

This conversion is common enough to make a name for.