bool-extras-0.4.0: A fold function for Bool

Safe HaskellSafe-Inferred

Data.Bool.Extras

Contents

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

Main function

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

Defines the fold over a boolean value.

Returns its first argument when applied to False, returns its second argument when applied to True.

Comparable to the maybe or either functions for their respective data types.

Other functions

mwhen :: Monoid a => a -> Bool -> aSource

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 aSource

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 bSource

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 aSource

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 aSource

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 -> rSource

Catamorphism for booleans.

ana :: (b -> Bool) -> b -> BoolSource

Anamorphism for booleans.