A convenient set of useful conditional operators.
- if' :: Bool -> a -> a -> a
- (??) :: a -> a -> Bool -> a
- bool :: a -> a -> Bool -> a
- select :: (a -> Bool) -> (a -> b) -> (a -> b) -> a -> b
- cond :: [(Bool, a)] -> a
- condPlus :: MonadPlus m => [(Bool, a)] -> m a
- ifM :: Monad m => m Bool -> m a -> m a -> m a
- (<||>) :: Monad m => m Bool -> m Bool -> m Bool
- (<&&>) :: Monad m => m Bool -> m Bool -> m Bool
- condM :: Monad m => [(m Bool, m a)] -> m a
- condPlusM :: MonadPlus m => [(m Bool, m a)] -> m a
Simple conditional operators
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.
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
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 )]