module Control.Bool (
bool
, notF
, (<||>)
, (<&&>)
, aguard'
, notM
, (<|=>)
, (<&=>)
, guard'
, guardM'
, whenM
, unlessM
) where
import Control.Applicative
import Control.Monad
import Data.Monoid
infixr 3 <&&>, <&=>
infixr 2 <||>, <|=>
bool :: a -> a -> Bool -> a
bool x _ False = x
bool _ y True = y
notF :: Functor f => f Bool -> f Bool
notF = fmap not
notM :: Monad m => m Bool -> m Bool
notM = liftM not
(<&&>) :: Applicative f => f Bool -> f Bool -> f Bool
(<&&>) = liftA2 (&&)
(<&=>) :: Monad m => m Bool -> m Bool -> m Bool
(<&=>) = liftM2 (&&)
(<||>) :: Applicative f => f Bool -> f Bool -> f Bool
(<||>) = liftA2 (||)
(<|=>) :: Monad m => m Bool -> m Bool -> m Bool
(<|=>) = liftM2 (||)
whenM :: (Monoid a, Monad m) => m Bool -> m a -> m a
whenM mp m = mp >>= bool (return mempty) m
unlessM :: (Monoid a, Monad m) => m Bool -> m a -> m a
unlessM mp m = mp >>= bool m (return mempty)
guard' :: MonadPlus m => Bool -> a -> m a
guard' b a = bool mzero (return a) b
aguard' :: Alternative m => Bool -> a -> m a
aguard' b a = bool empty (pure a) b
guardM' :: MonadPlus m => m Bool -> a -> m a
guardM' mp a = mp >>= flip guard' a