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
Other functions
mwhen :: Monoid a => a -> Bool -> a Source #
Boolean operation for monoids.
Returns its first argument when applied to True
,
returns mempty
when applied to False
.
mwhenM :: (Monad m, Monoid a) => m a -> Bool -> m a Source #
Boolean operation for monads, with a monoid default.
Return its first argument when applied to True
,
returns `return mempty' when applied to False
.
whenA :: Arrow a => a b b -> Bool -> a b b Source #
Boolean operation for arrows.
Returns its first argument when applied to True
,
returns returnA
when applied to False
.
whenC :: Category cat => cat a a -> Bool -> cat a a Source #
Boolean operation for categories.
Returns its first argument when applied to True
,
returns Control.Category.
id
when applied to False
.
whenM :: Monad m => (a -> m a) -> Bool -> a -> m a Source #
Boolean operation for monads.
Returns its first argument when applied to True
,
returns return
when applied to False
.
Control.Monad.
when
can be expressed in terms of whenM
, like so:
when :: Monad m => Bool -> m () -> m () when b m = (const m `whenM` b) ()
Morphisms
type BoolAlgebra r = (r, r) Source #
Algebra for Bool data type.
The first field of the pair represents the False
value,
the second field represents the True
value.
cata :: BoolAlgebra r -> Bool -> r Source #
Catamorphism for booleans.