cond-0.0.1: Basic conditional operators with monadic variants.

Safe HaskellSafe-Infered

Control.Cond

Contents

Description

A convenient set of useful conditional operators.

Synopsis

Simple conditional operators

if' :: Bool -> a -> a -> aSource

A simple conditional function.

(??) :: a -> a -> Bool -> aSource

if' with the Bool argument at the end (infixr 1).

bool :: a -> a -> Bool -> aSource

A catamorphism for the Bool type. This is analogous to foldr, maybe, and either. The first argument is the false case, the second argument is the true case, and the last argument is the predicate value.

Higher-order conditional

select :: (a -> Bool) -> (a -> b) -> (a -> b) -> a -> bSource

Composes a predicate function and 2 functions into a single function. The first function is called when the predicate yields True, the second when the predicate yields False.

Lisp-style conditional operators

cond :: [(Bool, a)] -> aSource

Lisp-style conditionals. If no conditions match, then a runtime exception is thrown. Here's a trivial example:

   signum x = cond [(x > 0     , 1 )
                   ,(x < 0     , -1)
                   ,(otherwise , 0 )]

condPlus :: MonadPlus m => [(Bool, a)] -> m aSource

Lisp-style conditionals generalized over MonadPlus. If no conditions match, then the result is mzero. This is a safer variant of cond.

Lifted conditional and boolean operators

ifM :: Monad m => m Bool -> m a -> m a -> m aSource

if' lifted to Monad. Unlike liftM3 if', this is short-circuiting in the monad, such that only the predicate action and one of the remaining argument actions are executed.

(<||>) :: Monad m => m Bool -> m Bool -> m BoolSource

Lifted boolean or. Unlike liftM2 (||), This function is short-circuiting in the monad. Fixity is the same as || (infixr 2).

(<&&>) :: Monad m => m Bool -> m Bool -> m BoolSource

Lifted boolean and. Unlike liftM2 (&&), this function is short-circuiting in the monad. Fixity is the same as && (infxr 3).

notM :: Monad m => m Bool -> m BoolSource

Lifted boolean negation.

condM :: Monad m => [(m Bool, m a)] -> m aSource

cond lifted to Monad. If no conditions match, a runtime exception is thrown.

condPlusM :: MonadPlus m => [(m Bool, m a)] -> m aSource

condPlus lifted to Monad. If no conditions match, then mzero is returned.

Lifted guard and when

guardM :: MonadPlus m => m Bool -> m ()Source

a variant of guard with a monadic predicate.

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

a variant of when with a monadic predicate.

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

a variant of unless with a monadic predicate.