-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | An Either monad transformer
--
-- Drop in alternative to ExceptT. Uses a pattern synonym to maintain
-- compatibility with the old EitherT types but is actually ExceptT under
-- the covers.
@package transformers-either
@version 0.1.3
-- | This monad transformer extends Control.Monad.Trans.Except with
-- a more familar Either naming.
module Control.Monad.Trans.Either
-- | Type alias for ExceptT
type EitherT = ExceptT
pattern EitherT :: m (Either x a) -> ExceptT x m a
-- | Constructor for computations in the either monad. (The inverse of
-- runEitherT).
newEitherT :: m (Either x a) -> EitherT x m a
-- | Extractor for computations in the either monad. (The inverse of
-- newEitherT).
runEitherT :: EitherT x m a -> m (Either x a)
-- | Map over both arguments at the same time.
--
-- Specialised version of bimap for EitherT.
eitherT :: Monad m => (x -> m b) -> (a -> m b) -> EitherT x m a -> m b
-- | Constructor for left computations.
left :: Monad m => x -> EitherT x m a
-- | Constructor for right computations.
right :: Monad m => a -> EitherT x m a
mapEitherT :: (m (Either x a) -> n (Either y b)) -> EitherT x m a -> EitherT y n b
-- | Hoist an Either into an EitherT m.
hoistEither :: Monad m => Either x a -> EitherT x m a
-- | Map the unwrapped computation using the given function.
bimapEitherT :: Functor m => (x -> y) -> (a -> b) -> EitherT x m a -> EitherT y m b
-- | Map the Left unwrapped computation using the given function.
firstEitherT :: Functor m => (x -> y) -> EitherT x m a -> EitherT y m a
-- | Map the Right unwrapped computation using the given function.
secondEitherT :: Functor m => (a -> b) -> EitherT x m a -> EitherT x m b
-- | Hoist Maybe a into Right a.
hoistMaybe :: Monad m => x -> Maybe a -> EitherT x m a
-- | Hoist Either m into an Either n.
hoistEitherT :: (forall b. m b -> n b) -> EitherT x m a -> EitherT x n a
-- | Try an IO action inside an EitherT. If the IO
-- action throws an IOException, catch it and wrap it with the
-- provided handler to convert it to the error type of the EitherT
-- transformer. Exceptions other than IOException will escape the
-- EitherT transformer.
--
-- Note: IOError is a type synonym for IOException.
handleIOEitherT :: MonadIO m => (IOException -> x) -> IO a -> EitherT x m a
-- | Try any monad action and catch the specified exception, wrapping it to
-- convert it to the error type of the EitherT transformer.
-- Exceptions other that the specified exception type will escape the
-- EitherT transformer.
--
--
-- - Warning*: This function should be used with caution! In
-- particular, it is bad practice to catch SomeException because
-- that includes asynchronous exceptions like stack/heap overflow, thread
-- killed and user interrupt. Trying to handle StackOverflow,
-- HeapOverflow and ThreadKilled exceptions could cause
-- your program to crash or behave in unexpected ways.
--
handleEitherT :: (MonadCatch m, Exception e) => (e -> x) -> m a -> EitherT x m a
-- | Try a monad action and catch any of the exceptions caught by the
-- provided handlers. The handler for each exception type needs to wrap
-- it to convert it to the error type of the EitherT transformer.
-- Exceptions not explicitly handled by the provided handlers will escape
-- the EitherT transformer.
handlesEitherT :: (Foldable f, MonadCatch m) => f (Handler m x) -> m a -> EitherT x m a
-- | Handle an error. Equivalent to handleError in mtl package.
handleLeftT :: Monad m => (e -> EitherT e m a) -> EitherT e m a -> EitherT e m a
-- | Flipped handleIOEitherT.
catchIOEitherT :: MonadIO m => IO a -> (IOException -> x) -> EitherT x m a
-- | Flipped handleEitherT.
catchEitherT :: (MonadCatch m, Exception e) => m a -> (e -> x) -> EitherT x m a
-- | Flipped handlesEitherT.
catchesEitherT :: (Foldable f, MonadCatch m) => m a -> f (Handler m x) -> EitherT x m a
-- | Flipped handleLeftT.
catchLeftT :: Monad m => EitherT e m a -> (e -> EitherT e m a) -> EitherT e m a
-- | Acquire a resource in EitherT and then perform an action with
-- it, cleaning up afterwards regardless of left.
--
-- This function does not clean up in the event of an exception. Prefer
-- bracketExceptionT in any impure setting.
bracketEitherT :: Monad m => EitherT e m a -> (a -> EitherT e m b) -> (a -> EitherT e m c) -> EitherT e m c
-- | Acquire a resource in EitherT and then perform an action with it,
-- cleaning up afterwards regardless of left or exception.
--
-- Like bracketEitherT, but the cleanup is called even when the
-- bracketed function throws an exception. Exceptions in the bracketed
-- function are caught to allow the cleanup to run and then rethrown.
bracketExceptionT :: MonadMask m => EitherT e m a -> (a -> EitherT e m c) -> (a -> EitherT e m b) -> EitherT e m b
-- | Convert an Either to a Maybe and execute the supplied handler in the
-- Left case.
hushM :: Monad m => Either e a -> (e -> m ()) -> m (Maybe a)
-- | Handle the Left constructor in returned Either.
onLeft :: forall e x m a. Monad m => (e -> ExceptT x m a) -> EitherT x m (Either e a) -> EitherT x m a
-- | Handle the Nothing constructor in returned Maybe.
onNothing :: forall x m a. Monad m => EitherT x m a -> EitherT x m (Maybe a) -> EitherT x m a
module Control.Monad.Trans.Either.Exit
-- | orDieWithCode with an exit code of 1 in case of an error
orDie :: (e -> Text) -> EitherT e IO a -> IO a
-- | An idiom for failing hard on EitherT errors.
--
--
-- - This really dies*. There is no other way to say it.
--
--
-- The reason it lives with command line parser tooling, is that it is
-- the only valid place to actually exit like this. Be appropriately
-- wary.
orDieWithCode :: Int -> (e -> Text) -> EitherT e IO a -> IO a