| Safe Haskell | Safe |
|---|---|
| Language | Haskell98 |
Data.Bool.Extras
Description
This module provides some convenient functions for dealing with Booleans.
The most important one being bool, a function that can be used in place of
the build-in if then else-syntax.
Synopsis
- bool :: a -> a -> Bool -> a
- mwhen :: Monoid a => a -> Bool -> a
- mwhenM :: (Monad m, Monoid a) => m a -> Bool -> m a
- whenA :: Arrow a => a b b -> Bool -> a b b
- whenC :: Category cat => cat a a -> Bool -> cat a a
- whenM :: Monad m => (a -> m a) -> Bool -> a -> m a
- type BoolAlgebra r = (r, r)
- cata :: BoolAlgebra r -> Bool -> r
- ana :: (b -> Bool) -> b -> Bool
Main function
bool :: a -> a -> Bool -> a Source #
Case analysis for the Bool type. evaluates to bool x y px
when p is False, and evaluates to y when p is True.
This is equivalent to if p then y else x; that is, one can
think of it as an if-then-else construct with its arguments
reordered.
Examples
Basic usage:
>>>bool "foo" "bar" True"bar">>>bool "foo" "bar" False"foo"
Confirm that and bool x y pif p then y else x are
equivalent:
>>>let p = True; x = "bar"; y = "foo">>>bool x y p == if p then y else xTrue>>>let p = False>>>bool x y p == if p then y else xTrue
Since: base-4.7.0.0
Other functions
Morphisms
type BoolAlgebra r = (r, r) Source #
cata :: BoolAlgebra r -> Bool -> r Source #
Catamorphism for booleans.