module Control.Error.Util (
module Control.Error.Util,
module X,
) where
import Control.Monad (unless)
import Control.Monad.Trans.Except as X
import qualified Data.Maybe as Maybe
import Prelude
infixl 4 <?>
(<?>) :: Maybe b -> a -> Either a b
val <?> m = Maybe.maybe (Left m) Right val
infixl 4 <?&>
(<?&>) :: Either a (Maybe b) -> a -> Either a b
val <?&> m = Maybe.maybe (Left m) Right =<< val
infixl 4 <??>
(<??>) :: Monad m => Maybe b -> a -> ExceptT a m b
val <??> m = Maybe.maybe (throwE m) return val
infixl 4 <??&>
(<??&>) :: Monad m => ExceptT a m (Maybe b) -> a -> ExceptT a m b
val <??&> m = Maybe.maybe (throwE m) return =<< val
infixl 4 <?.>
(<?.>) :: Monad m => Maybe b -> String -> m b
val <?.> m = Maybe.maybe (fail m) return val
infixl 4 <?&.>
(<?&.>) :: Monad m => m (Maybe b) -> String -> m b
val <?&.> m = Maybe.maybe (fail m) return =<< val
assert :: Bool -> a -> Either a ()
assert condition msg = unless condition $ Left msg
assertE :: Monad m => Bool -> a -> ExceptT a m ()
assertE condition msg = unless condition $ throwE msg
assertM :: Monad m => Bool -> String -> m ()
assertM condition msg = unless condition $ fail msg