{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}

module Control.Monad.Except.IO
    ( ExceptIOT (..)
    , runExceptIOT
    , module Control.Monad.Error.Class
    , modifyError
    ) where

import Control.Applicative
import Control.Monad
import Control.Monad.Catch hiding (catch, try)
import Control.Monad.Error.Class hiding (modifyError)
import qualified Control.Monad.Except as Except
import Control.Monad.Fix
import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Writer
import UnliftIO

-- | This type is useful for providing a 'MonadError' constraint to an 'IO'
-- action for a given type. It can replace 'ExceptT'.
--
-- Note that 'catchError' will use the behavior from "UnliftIO" - so catch won't
-- catch an asynchronous exception.
--
-- @since 0.1.0.0
newtype ExceptIOT e m a = ExceptIOT { forall e (m :: * -> *) a. ExceptIOT e m a -> m a
unsafeRunExceptIOT :: m a }
    deriving newtype
        ( (forall a b. (a -> b) -> ExceptIOT e m a -> ExceptIOT e m b)
-> (forall a b. a -> ExceptIOT e m b -> ExceptIOT e m a)
-> Functor (ExceptIOT e m)
forall a b. a -> ExceptIOT e m b -> ExceptIOT e m a
forall a b. (a -> b) -> ExceptIOT e m a -> ExceptIOT e m b
forall e (m :: * -> *) a b.
Functor m =>
a -> ExceptIOT e m b -> ExceptIOT e m a
forall e (m :: * -> *) a b.
Functor m =>
(a -> b) -> ExceptIOT e m a -> ExceptIOT e m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall e (m :: * -> *) a b.
Functor m =>
(a -> b) -> ExceptIOT e m a -> ExceptIOT e m b
fmap :: forall a b. (a -> b) -> ExceptIOT e m a -> ExceptIOT e m b
$c<$ :: forall e (m :: * -> *) a b.
Functor m =>
a -> ExceptIOT e m b -> ExceptIOT e m a
<$ :: forall a b. a -> ExceptIOT e m b -> ExceptIOT e m a
Functor, Functor (ExceptIOT e m)
Functor (ExceptIOT e m) =>
(forall a. a -> ExceptIOT e m a)
-> (forall a b.
    ExceptIOT e m (a -> b) -> ExceptIOT e m a -> ExceptIOT e m b)
-> (forall a b c.
    (a -> b -> c)
    -> ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m c)
-> (forall a b.
    ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m b)
-> (forall a b.
    ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m a)
-> Applicative (ExceptIOT e m)
forall a. a -> ExceptIOT e m a
forall a b. ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m a
forall a b. ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m b
forall a b.
ExceptIOT e m (a -> b) -> ExceptIOT e m a -> ExceptIOT e m b
forall a b c.
(a -> b -> c)
-> ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m c
forall e (m :: * -> *). Applicative m => Functor (ExceptIOT e m)
forall e (m :: * -> *) a. Applicative m => a -> ExceptIOT e m a
forall e (m :: * -> *) a b.
Applicative m =>
ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m a
forall e (m :: * -> *) a b.
Applicative m =>
ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m b
forall e (m :: * -> *) a b.
Applicative m =>
ExceptIOT e m (a -> b) -> ExceptIOT e m a -> ExceptIOT e m b
forall e (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall e (m :: * -> *) a. Applicative m => a -> ExceptIOT e m a
pure :: forall a. a -> ExceptIOT e m a
$c<*> :: forall e (m :: * -> *) a b.
Applicative m =>
ExceptIOT e m (a -> b) -> ExceptIOT e m a -> ExceptIOT e m b
<*> :: forall a b.
ExceptIOT e m (a -> b) -> ExceptIOT e m a -> ExceptIOT e m b
$cliftA2 :: forall e (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m c
liftA2 :: forall a b c.
(a -> b -> c)
-> ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m c
$c*> :: forall e (m :: * -> *) a b.
Applicative m =>
ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m b
*> :: forall a b. ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m b
$c<* :: forall e (m :: * -> *) a b.
Applicative m =>
ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m a
<* :: forall a b. ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m a
Applicative, Applicative (ExceptIOT e m)
Applicative (ExceptIOT e m) =>
(forall a b.
 ExceptIOT e m a -> (a -> ExceptIOT e m b) -> ExceptIOT e m b)
-> (forall a b.
    ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m b)
-> (forall a. a -> ExceptIOT e m a)
-> Monad (ExceptIOT e m)
forall a. a -> ExceptIOT e m a
forall a b. ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m b
forall a b.
ExceptIOT e m a -> (a -> ExceptIOT e m b) -> ExceptIOT e m b
forall e (m :: * -> *). Monad m => Applicative (ExceptIOT e m)
forall e (m :: * -> *) a. Monad m => a -> ExceptIOT e m a
forall e (m :: * -> *) a b.
Monad m =>
ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m b
forall e (m :: * -> *) a b.
Monad m =>
ExceptIOT e m a -> (a -> ExceptIOT e m b) -> ExceptIOT e m b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall e (m :: * -> *) a b.
Monad m =>
ExceptIOT e m a -> (a -> ExceptIOT e m b) -> ExceptIOT e m b
>>= :: forall a b.
ExceptIOT e m a -> (a -> ExceptIOT e m b) -> ExceptIOT e m b
$c>> :: forall e (m :: * -> *) a b.
Monad m =>
ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m b
>> :: forall a b. ExceptIOT e m a -> ExceptIOT e m b -> ExceptIOT e m b
$creturn :: forall e (m :: * -> *) a. Monad m => a -> ExceptIOT e m a
return :: forall a. a -> ExceptIOT e m a
Monad, Monad (ExceptIOT e m)
Monad (ExceptIOT e m) =>
(forall a. IO a -> ExceptIOT e m a) -> MonadIO (ExceptIOT e m)
forall a. IO a -> ExceptIOT e m a
forall e (m :: * -> *). MonadIO m => Monad (ExceptIOT e m)
forall e (m :: * -> *) a. MonadIO m => IO a -> ExceptIOT e m a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
$cliftIO :: forall e (m :: * -> *) a. MonadIO m => IO a -> ExceptIOT e m a
liftIO :: forall a. IO a -> ExceptIOT e m a
MonadIO, Monad (ExceptIOT e m)
Alternative (ExceptIOT e m)
(Alternative (ExceptIOT e m), Monad (ExceptIOT e m)) =>
(forall a. ExceptIOT e m a)
-> (forall a.
    ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a)
-> MonadPlus (ExceptIOT e m)
forall a. ExceptIOT e m a
forall a. ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
forall e (m :: * -> *). MonadPlus m => Monad (ExceptIOT e m)
forall e (m :: * -> *). MonadPlus m => Alternative (ExceptIOT e m)
forall e (m :: * -> *) a. MonadPlus m => ExceptIOT e m a
forall e (m :: * -> *) a.
MonadPlus m =>
ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
forall (m :: * -> *).
(Alternative m, Monad m) =>
(forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m
$cmzero :: forall e (m :: * -> *) a. MonadPlus m => ExceptIOT e m a
mzero :: forall a. ExceptIOT e m a
$cmplus :: forall e (m :: * -> *) a.
MonadPlus m =>
ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
mplus :: forall a. ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
MonadPlus, Applicative (ExceptIOT e m)
Applicative (ExceptIOT e m) =>
(forall a. ExceptIOT e m a)
-> (forall a.
    ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a)
-> (forall a. ExceptIOT e m a -> ExceptIOT e m [a])
-> (forall a. ExceptIOT e m a -> ExceptIOT e m [a])
-> Alternative (ExceptIOT e m)
forall a. ExceptIOT e m a
forall a. ExceptIOT e m a -> ExceptIOT e m [a]
forall a. ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
forall e (m :: * -> *).
Alternative m =>
Applicative (ExceptIOT e m)
forall e (m :: * -> *) a. Alternative m => ExceptIOT e m a
forall e (m :: * -> *) a.
Alternative m =>
ExceptIOT e m a -> ExceptIOT e m [a]
forall e (m :: * -> *) a.
Alternative m =>
ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
forall (f :: * -> *).
Applicative f =>
(forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
$cempty :: forall e (m :: * -> *) a. Alternative m => ExceptIOT e m a
empty :: forall a. ExceptIOT e m a
$c<|> :: forall e (m :: * -> *) a.
Alternative m =>
ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
<|> :: forall a. ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
$csome :: forall e (m :: * -> *) a.
Alternative m =>
ExceptIOT e m a -> ExceptIOT e m [a]
some :: forall a. ExceptIOT e m a -> ExceptIOT e m [a]
$cmany :: forall e (m :: * -> *) a.
Alternative m =>
ExceptIOT e m a -> ExceptIOT e m [a]
many :: forall a. ExceptIOT e m a -> ExceptIOT e m [a]
Alternative
        , NonEmpty (ExceptIOT e m a) -> ExceptIOT e m a
ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
(ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a)
-> (NonEmpty (ExceptIOT e m a) -> ExceptIOT e m a)
-> (forall b.
    Integral b =>
    b -> ExceptIOT e m a -> ExceptIOT e m a)
-> Semigroup (ExceptIOT e m a)
forall b. Integral b => b -> ExceptIOT e m a -> ExceptIOT e m a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall e (m :: * -> *) a.
Semigroup (m a) =>
NonEmpty (ExceptIOT e m a) -> ExceptIOT e m a
forall e (m :: * -> *) a.
Semigroup (m a) =>
ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
forall e (m :: * -> *) a b.
(Semigroup (m a), Integral b) =>
b -> ExceptIOT e m a -> ExceptIOT e m a
$c<> :: forall e (m :: * -> *) a.
Semigroup (m a) =>
ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
<> :: ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
$csconcat :: forall e (m :: * -> *) a.
Semigroup (m a) =>
NonEmpty (ExceptIOT e m a) -> ExceptIOT e m a
sconcat :: NonEmpty (ExceptIOT e m a) -> ExceptIOT e m a
$cstimes :: forall e (m :: * -> *) a b.
(Semigroup (m a), Integral b) =>
b -> ExceptIOT e m a -> ExceptIOT e m a
stimes :: forall b. Integral b => b -> ExceptIOT e m a -> ExceptIOT e m a
Semigroup, Semigroup (ExceptIOT e m a)
ExceptIOT e m a
Semigroup (ExceptIOT e m a) =>
ExceptIOT e m a
-> (ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a)
-> ([ExceptIOT e m a] -> ExceptIOT e m a)
-> Monoid (ExceptIOT e m a)
[ExceptIOT e m a] -> ExceptIOT e m a
ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall e (m :: * -> *) a.
Monoid (m a) =>
Semigroup (ExceptIOT e m a)
forall e (m :: * -> *) a. Monoid (m a) => ExceptIOT e m a
forall e (m :: * -> *) a.
Monoid (m a) =>
[ExceptIOT e m a] -> ExceptIOT e m a
forall e (m :: * -> *) a.
Monoid (m a) =>
ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
$cmempty :: forall e (m :: * -> *) a. Monoid (m a) => ExceptIOT e m a
mempty :: ExceptIOT e m a
$cmappend :: forall e (m :: * -> *) a.
Monoid (m a) =>
ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
mappend :: ExceptIOT e m a -> ExceptIOT e m a -> ExceptIOT e m a
$cmconcat :: forall e (m :: * -> *) a.
Monoid (m a) =>
[ExceptIOT e m a] -> ExceptIOT e m a
mconcat :: [ExceptIOT e m a] -> ExceptIOT e m a
Monoid, MonadIO (ExceptIOT e m)
MonadIO (ExceptIOT e m) =>
(forall b.
 ((forall a. ExceptIOT e m a -> IO a) -> IO b) -> ExceptIOT e m b)
-> MonadUnliftIO (ExceptIOT e m)
forall b.
((forall a. ExceptIOT e m a -> IO a) -> IO b) -> ExceptIOT e m b
forall e (m :: * -> *). MonadUnliftIO m => MonadIO (ExceptIOT e m)
forall e (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. ExceptIOT e m a -> IO a) -> IO b) -> ExceptIOT e m b
forall (m :: * -> *).
MonadIO m =>
(forall b. ((forall a. m a -> IO a) -> IO b) -> m b)
-> MonadUnliftIO m
$cwithRunInIO :: forall e (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. ExceptIOT e m a -> IO a) -> IO b) -> ExceptIOT e m b
withRunInIO :: forall b.
((forall a. ExceptIOT e m a -> IO a) -> IO b) -> ExceptIOT e m b
MonadUnliftIO, MonadReader r, MonadState s
        , MonadWriter w, Monad (ExceptIOT e m)
Monad (ExceptIOT e m) =>
(forall a. (a -> ExceptIOT e m a) -> ExceptIOT e m a)
-> MonadFix (ExceptIOT e m)
forall a. (a -> ExceptIOT e m a) -> ExceptIOT e m a
forall e (m :: * -> *). MonadFix m => Monad (ExceptIOT e m)
forall e (m :: * -> *) a.
MonadFix m =>
(a -> ExceptIOT e m a) -> ExceptIOT e m a
forall (m :: * -> *).
Monad m =>
(forall a. (a -> m a) -> m a) -> MonadFix m
$cmfix :: forall e (m :: * -> *) a.
MonadFix m =>
(a -> ExceptIOT e m a) -> ExceptIOT e m a
mfix :: forall a. (a -> ExceptIOT e m a) -> ExceptIOT e m a
MonadFix, Monad (ExceptIOT e m)
Monad (ExceptIOT e m) =>
(forall a. String -> ExceptIOT e m a) -> MonadFail (ExceptIOT e m)
forall a. String -> ExceptIOT e m a
forall e (m :: * -> *). MonadFail m => Monad (ExceptIOT e m)
forall e (m :: * -> *) a. MonadFail m => String -> ExceptIOT e m a
forall (m :: * -> *).
Monad m =>
(forall a. String -> m a) -> MonadFail m
$cfail :: forall e (m :: * -> *) a. MonadFail m => String -> ExceptIOT e m a
fail :: forall a. String -> ExceptIOT e m a
MonadFail, Monad (ExceptIOT e m)
Monad (ExceptIOT e m) =>
(forall e a. (HasCallStack, Exception e) => e -> ExceptIOT e m a)
-> MonadThrow (ExceptIOT e m)
forall e a. (HasCallStack, Exception e) => e -> ExceptIOT e m a
forall e (m :: * -> *). MonadThrow m => Monad (ExceptIOT e m)
forall e (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> ExceptIOT e m a
forall (m :: * -> *).
Monad m =>
(forall e a. (HasCallStack, Exception e) => e -> m a)
-> MonadThrow m
$cthrowM :: forall e (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> ExceptIOT e m a
throwM :: forall e a. (HasCallStack, Exception e) => e -> ExceptIOT e m a
MonadThrow, MonadThrow (ExceptIOT e m)
MonadThrow (ExceptIOT e m) =>
(forall e a.
 (HasCallStack, Exception e) =>
 ExceptIOT e m a -> (e -> ExceptIOT e m a) -> ExceptIOT e m a)
-> MonadCatch (ExceptIOT e m)
forall e a.
(HasCallStack, Exception e) =>
ExceptIOT e m a -> (e -> ExceptIOT e m a) -> ExceptIOT e m a
forall e (m :: * -> *). MonadCatch m => MonadThrow (ExceptIOT e m)
forall e (m :: * -> *) e a.
(MonadCatch m, HasCallStack, Exception e) =>
ExceptIOT e m a -> (e -> ExceptIOT e m a) -> ExceptIOT e m a
forall (m :: * -> *).
MonadThrow m =>
(forall e a.
 (HasCallStack, Exception e) =>
 m a -> (e -> m a) -> m a)
-> MonadCatch m
$ccatch :: forall e (m :: * -> *) e a.
(MonadCatch m, HasCallStack, Exception e) =>
ExceptIOT e m a -> (e -> ExceptIOT e m a) -> ExceptIOT e m a
catch :: forall e a.
(HasCallStack, Exception e) =>
ExceptIOT e m a -> (e -> ExceptIOT e m a) -> ExceptIOT e m a
MonadCatch, MonadCatch (ExceptIOT e m)
MonadCatch (ExceptIOT e m) =>
(forall b.
 HasCallStack =>
 ((forall a. ExceptIOT e m a -> ExceptIOT e m a) -> ExceptIOT e m b)
 -> ExceptIOT e m b)
-> (forall b.
    HasCallStack =>
    ((forall a. ExceptIOT e m a -> ExceptIOT e m a) -> ExceptIOT e m b)
    -> ExceptIOT e m b)
-> (forall a b c.
    HasCallStack =>
    ExceptIOT e m a
    -> (a -> ExitCase b -> ExceptIOT e m c)
    -> (a -> ExceptIOT e m b)
    -> ExceptIOT e m (b, c))
-> MonadMask (ExceptIOT e m)
forall b.
HasCallStack =>
((forall a. ExceptIOT e m a -> ExceptIOT e m a) -> ExceptIOT e m b)
-> ExceptIOT e m b
forall a b c.
HasCallStack =>
ExceptIOT e m a
-> (a -> ExitCase b -> ExceptIOT e m c)
-> (a -> ExceptIOT e m b)
-> ExceptIOT e m (b, c)
forall e (m :: * -> *). MonadMask m => MonadCatch (ExceptIOT e m)
forall e (m :: * -> *) b.
(MonadMask m, HasCallStack) =>
((forall a. ExceptIOT e m a -> ExceptIOT e m a) -> ExceptIOT e m b)
-> ExceptIOT e m b
forall e (m :: * -> *) a b c.
(MonadMask m, HasCallStack) =>
ExceptIOT e m a
-> (a -> ExitCase b -> ExceptIOT e m c)
-> (a -> ExceptIOT e m b)
-> ExceptIOT e m (b, c)
forall (m :: * -> *).
MonadCatch m =>
(forall b. HasCallStack => ((forall a. m a -> m a) -> m b) -> m b)
-> (forall b.
    HasCallStack =>
    ((forall a. m a -> m a) -> m b) -> m b)
-> (forall a b c.
    HasCallStack =>
    m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c))
-> MonadMask m
$cmask :: forall e (m :: * -> *) b.
(MonadMask m, HasCallStack) =>
((forall a. ExceptIOT e m a -> ExceptIOT e m a) -> ExceptIOT e m b)
-> ExceptIOT e m b
mask :: forall b.
HasCallStack =>
((forall a. ExceptIOT e m a -> ExceptIOT e m a) -> ExceptIOT e m b)
-> ExceptIOT e m b
$cuninterruptibleMask :: forall e (m :: * -> *) b.
(MonadMask m, HasCallStack) =>
((forall a. ExceptIOT e m a -> ExceptIOT e m a) -> ExceptIOT e m b)
-> ExceptIOT e m b
uninterruptibleMask :: forall b.
HasCallStack =>
((forall a. ExceptIOT e m a -> ExceptIOT e m a) -> ExceptIOT e m b)
-> ExceptIOT e m b
$cgeneralBracket :: forall e (m :: * -> *) a b c.
(MonadMask m, HasCallStack) =>
ExceptIOT e m a
-> (a -> ExitCase b -> ExceptIOT e m c)
-> (a -> ExceptIOT e m b)
-> ExceptIOT e m (b, c)
generalBracket :: forall a b c.
HasCallStack =>
ExceptIOT e m a
-> (a -> ExitCase b -> ExceptIOT e m c)
-> (a -> ExceptIOT e m b)
-> ExceptIOT e m (b, c)
MonadMask
        )

-- |
--
-- @since 0.1.0.0
instance (MonadUnliftIO m, Exception e) => MonadError e (ExceptIOT e m) where
    throwError :: forall a. e -> ExceptIOT e m a
throwError = e -> ExceptIOT e m a
forall (m :: * -> *) e a. (MonadIO m, Exception e) => e -> m a
throwIO
    catchError :: forall a.
ExceptIOT e m a -> (e -> ExceptIOT e m a) -> ExceptIOT e m a
catchError = ExceptIOT e m a -> (e -> ExceptIOT e m a) -> ExceptIOT e m a
forall (m :: * -> *) e a.
(MonadUnliftIO m, Exception e) =>
m a -> (e -> m a) -> m a
catch

-- | Run an 'ExceptIOT' action. This catches the thrown exception, but only if
-- it is the @e@ that the type mentions. All other exceptions will remain
-- uncaught.
--
-- @since 0.1.0.0
runExceptIOT :: (Exception e, MonadUnliftIO m) => ExceptIOT e m a -> m (Either e a)
runExceptIOT :: forall e (m :: * -> *) a.
(Exception e, MonadUnliftIO m) =>
ExceptIOT e m a -> m (Either e a)
runExceptIOT = m a -> m (Either e a)
forall (m :: * -> *) e a.
(MonadUnliftIO m, Exception e) =>
m a -> m (Either e a)
try (m a -> m (Either e a))
-> (ExceptIOT e m a -> m a) -> ExceptIOT e m a -> m (Either e a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExceptIOT e m a -> m a
forall e (m :: * -> *) a. ExceptIOT e m a -> m a
unsafeRunExceptIOT

-- | Like 'Except.modifyError', but it selects the 'ExceptIOT' instance for 'IO'
-- exceptions instead of the 'ExceptT' instance with an 'Either' error.
--
-- @since 0.1.0.0
modifyError
    :: (Exception e, MonadUnliftIO m, MonadError e' m)
    => (e -> e') -> ExceptIOT e m a -> m a
modifyError :: forall e (m :: * -> *) e' a.
(Exception e, MonadUnliftIO m, MonadError e' m) =>
(e -> e') -> ExceptIOT e m a -> m a
modifyError e -> e'
f ExceptIOT e m a
action =
    ExceptIOT e m a -> m (Either e a)
forall e (m :: * -> *) a.
(Exception e, MonadUnliftIO m) =>
ExceptIOT e m a -> m (Either e a)
runExceptIOT ExceptIOT e m a
action m (Either e a) -> (Either e a -> m a) -> m a
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (e -> m a) -> (a -> m a) -> Either e a -> m a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (e' -> m a
forall a. e' -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (e' -> m a) -> (e -> e') -> e -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> e'
f) a -> m a
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure