Copyright | (C) 2017 Tim McGilchrist |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | timmcgil@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
This monad transformer extends Control.Monad.Trans.Except with a few more conveniences.
Synopsis
- newExceptT :: m (Either x a) -> ExceptT x m a
- runExceptT :: ExceptT e m a -> m (Either e a)
- exceptT :: Monad m => (x -> m b) -> (a -> m b) -> ExceptT x m a -> m b
- left :: Monad m => x -> ExceptT x m a
- right :: Monad m => a -> ExceptT x m a
- mapExceptT :: (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b
- hoistEither :: Monad m => Either x a -> ExceptT x m a
- bimapExceptT :: Functor m => (x -> y) -> (a -> b) -> ExceptT x m a -> ExceptT y m b
- firstExceptT :: Functor m => (x -> y) -> ExceptT x m a -> ExceptT y m a
- secondExceptT :: Functor m => (a -> b) -> ExceptT x m a -> ExceptT x m b
- hoistMaybe :: Monad m => x -> Maybe a -> ExceptT x m a
- hoistExceptT :: (forall b. m b -> n b) -> ExceptT x m a -> ExceptT x n a
- handleIOExceptT :: MonadIO m => (IOException -> x) -> IO a -> ExceptT x m a
- handleExceptT :: (MonadCatch m, Exception e) => (e -> x) -> m a -> ExceptT x m a
- handlesExceptT :: (Foldable f, MonadCatch m) => f (Handler m x) -> m a -> ExceptT x m a
- handleLeftT :: Monad m => (e -> ExceptT e m a) -> ExceptT e m a -> ExceptT e m a
- catchIOExceptT :: MonadIO m => IO a -> (IOException -> x) -> ExceptT x m a
- catchExceptT :: (MonadCatch m, Exception e) => m a -> (e -> x) -> ExceptT x m a
- catchesExceptT :: (Foldable f, MonadCatch m) => m a -> f (Handler m x) -> ExceptT x m a
- catchLeftT :: Monad m => ExceptT e m a -> (e -> ExceptT e m a) -> ExceptT e m a
- bracketExceptT :: Monad m => ExceptT e m a -> (a -> ExceptT e m b) -> (a -> ExceptT e m c) -> ExceptT e m c
- bracketExceptionT :: MonadMask m => ExceptT e m a -> (a -> ExceptT e m c) -> (a -> ExceptT e m b) -> ExceptT e m b
- hushM :: Monad m => Either e a -> (e -> m ()) -> m (Maybe a)
Control.Monad.Trans.Except.Extra
newExceptT :: m (Either x a) -> ExceptT x m a Source #
Constructor for computations in the ExceptT monad.
(The inverse of runExceptT
).
runExceptT :: ExceptT e m a -> m (Either e a) #
The inverse of ExceptT
.
exceptT :: Monad m => (x -> m b) -> (a -> m b) -> ExceptT x m a -> m b Source #
Map over both arguments at the same time.
Specialised version of bimap
for ExceptT
.
mapExceptT :: (m (Either e a) -> n (Either e' b)) -> ExceptT e m a -> ExceptT e' n b #
Map the unwrapped computation using the given function.
runExceptT
(mapExceptT
f m) = f (runExceptT
m)
bimapExceptT :: Functor m => (x -> y) -> (a -> b) -> ExceptT x m a -> ExceptT y m b Source #
Map the unwrapped computation using the given function.
Extensions
firstExceptT :: Functor m => (x -> y) -> ExceptT x m a -> ExceptT y m a Source #
Map the Left
unwrapped computation using the given function.
secondExceptT :: Functor m => (a -> b) -> ExceptT x m a -> ExceptT x m b Source #
Map the Right
unwrapped computation using the given function.
hoistExceptT :: (forall b. m b -> n b) -> ExceptT x m a -> ExceptT x n a Source #
handleIOExceptT :: MonadIO m => (IOException -> x) -> IO a -> ExceptT x m a Source #
Try an IO
action inside an ExceptT
. 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 ExceptT
transformer. Exceptions other than
IOException
will escape the ExceptT transformer.
Note: IOError
is a type synonym for IOException
.
handleExceptT :: (MonadCatch m, Exception e) => (e -> x) -> m a -> ExceptT x m a Source #
Try any monad action and catch the specified exception, wrapping it to
convert it to the error type of the ExceptT
transformer. Exceptions other
that the specified exception type will escape the ExceptT
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 handleStackOverflow
,HeapOverflow
andThreadKilled
exceptions could cause your program to crash or behave in unexpected ways.
handlesExceptT :: (Foldable f, MonadCatch m) => f (Handler m x) -> m a -> ExceptT x m a Source #
handleLeftT :: Monad m => (e -> ExceptT e m a) -> ExceptT e m a -> ExceptT e m a Source #
Handle an error. Equivalent to handleError
in mtl package.
catchIOExceptT :: MonadIO m => IO a -> (IOException -> x) -> ExceptT x m a Source #
Flipped handleIOExceptT
.
catchExceptT :: (MonadCatch m, Exception e) => m a -> (e -> x) -> ExceptT x m a Source #
Flipped handleExceptT
.
catchesExceptT :: (Foldable f, MonadCatch m) => m a -> f (Handler m x) -> ExceptT x m a Source #
Flipped handlesExceptT
.
catchLeftT :: Monad m => ExceptT e m a -> (e -> ExceptT e m a) -> ExceptT e m a Source #
Flipped handleLeftT
.
bracketExceptT :: Monad m => ExceptT e m a -> (a -> ExceptT e m b) -> (a -> ExceptT e m c) -> ExceptT e m c Source #
Acquire a resource in ExceptT
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.
bracketExceptionT :: MonadMask m => ExceptT e m a -> (a -> ExceptT e m c) -> (a -> ExceptT e m b) -> ExceptT e m b Source #
Acquire a resource in ExceptT and then perform an action with it,
cleaning up afterwards regardless of left
or exception.
Like bracketExceptT
, 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.