-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A fold function for Bool
--   
--   The <a>bool</a> function allows folding over boolean values.
--   
--   This is comparable to the <a>maybe</a> or <a>either</a> functions on
--   their respective types.
--   
--   The <a>bool</a> function is a replacement for the build-in <tt>if then
--   else</tt>-syntax. However, since it is a function, it can be partially
--   applied and passed around to higher order functions, like so:
--   
--   <pre>
--   ghci&gt; :m + Data.Bool.Extras
--   ghci&gt; let yesOrNo = bool "no" "yes"
--   ghci&gt; map yesOrNo [True, False, True]
--   ["yes", "no", "yes"]
--   </pre>
--   
--   Note that the arguments to <a>bool</a> are in the opposite order of
--   the <tt>if then else</tt>-syntax; First the false value, then the true
--   value, and finally the boolean.
@package bool-extras
@version 0.4.0


-- | This module provides some convenient functions for dealing with
--   Booleans.
--   
--   The most important one being <a>bool</a>, a function that can be used
--   in place of the build-in <tt>if then else</tt>-syntax.
module Data.Bool.Extras

-- | Case analysis for the <a>Bool</a> type. <tt><a>bool</a> x y p</tt>
--   evaluates to <tt>x</tt> when <tt>p</tt> is <a>False</a>, and evaluates
--   to <tt>y</tt> when <tt>p</tt> is <a>True</a>.
--   
--   This is equivalent to <tt>if p then y else x</tt>; that is, one can
--   think of it as an if-then-else construct with its arguments reordered.
--   
--   <h4><b>Examples</b></h4>
--   
--   Basic usage:
--   
--   <pre>
--   &gt;&gt;&gt; bool "foo" "bar" True
--   "bar"
--   
--   &gt;&gt;&gt; bool "foo" "bar" False
--   "foo"
--   </pre>
--   
--   Confirm that <tt><a>bool</a> x y p</tt> and <tt>if p then y else
--   x</tt> are equivalent:
--   
--   <pre>
--   &gt;&gt;&gt; let p = True; x = "bar"; y = "foo"
--   
--   &gt;&gt;&gt; bool x y p == if p then y else x
--   True
--   
--   &gt;&gt;&gt; let p = False
--   
--   &gt;&gt;&gt; bool x y p == if p then y else x
--   True
--   </pre>
bool :: a -> a -> Bool -> a

-- | Boolean operation for monoids.
--   
--   Returns its first argument when applied to <a>True</a>, returns
--   <a>mempty</a> when applied to <a>False</a>.
mwhen :: Monoid a => a -> Bool -> a

-- | Boolean operation for monads, with a monoid default.
--   
--   Return its first argument when applied to <a>True</a>, returns `return
--   mempty' when applied to <a>False</a>.
mwhenM :: (Monad m, Monoid a) => m a -> Bool -> m a

-- | Boolean operation for arrows.
--   
--   Returns its first argument when applied to <a>True</a>, returns
--   <a>returnA</a> when applied to <a>False</a>.
whenA :: Arrow a => a b b -> Bool -> a b b

-- | Boolean operation for categories.
--   
--   Returns its first argument when applied to <a>True</a>, returns
--   <tt>Control.Category.</tt><a>id</a> when applied to <a>False</a>.
whenC :: Category cat => cat a a -> Bool -> cat a a

-- | Boolean operation for monads.
--   
--   Returns its first argument when applied to <a>True</a>, returns
--   <a>return</a> when applied to <a>False</a>.
--   
--   <tt>Control.Monad.</tt><a>when</a> can be expressed in terms of
--   <a>whenM</a>, like so:
--   
--   <pre>
--   when :: Monad m =&gt; Bool -&gt; m () -&gt; m ()
--   when b m = (const m `whenM` b) ()
--   </pre>
whenM :: Monad m => (a -> m a) -> Bool -> a -> m a

-- | Algebra for Bool data type.
--   
--   The first field of the pair represents the <a>False</a> value, the
--   second field represents the <a>True</a> value.
type BoolAlgebra r = (r, r)

-- | Catamorphism for booleans.
cata :: BoolAlgebra r -> Bool -> r

-- | Anamorphism for booleans.
ana :: (b -> Bool) -> b -> Bool
