module Control.Error.Util where
import Control.Monad
import Control.Monad.Trans.Either
import Control.Monad.Trans.Maybe
hush :: Either a b -> Maybe b
hush e = case e of
Left _ -> Nothing
Right b -> Just b
hushT :: (Monad m) => EitherT a m b -> MaybeT m b
hushT = MaybeT . liftM hush . runEitherT
note :: a -> Maybe b -> Either a b
note a m = case m of
Nothing -> Left a
Just b -> Right b
noteT :: (Monad m) => a -> MaybeT m b -> EitherT a m b
noteT a = EitherT . liftM (note a) . runMaybeT
liftMaybe :: (Monad m) => Maybe b -> MaybeT m b
liftMaybe = MaybeT . return
liftEither :: (Monad m) => Either a b -> EitherT a m b
liftEither = EitherT . return