bool-extras-0.4.0: A fold function for Bool

Safe HaskellSafe-Inferred
LanguageHaskell98

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

Case analysis for the Bool type. bool a b p evaluates to a when p is False, and evaluates to b when p is True.

Since: 4.7.0.0

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.

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

Anamorphism for booleans.