summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwarlock <>2017-12-07 11:27:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-12-07 11:27:00 (GMT)
commitda5558cdeef2385160a4ad979bcec1ddf8bf8251 (patch)
tree21af3b0d8254254d57430d17f2a6640929b3199a
parent0f66b29b0903fbaa6f5f2cf366d1d5fa478d0e1d (diff)
version 0.4.1HEAD0.4.1master
-rw-r--r--errors-ext.cabal2
-rw-r--r--src/Control/Error/Extensions.hs9
2 files changed, 8 insertions, 3 deletions
diff --git a/errors-ext.cabal b/errors-ext.cabal
index a73faa4..bf56fe9 100644
--- a/errors-ext.cabal
+++ b/errors-ext.cabal
@@ -1,5 +1,5 @@
name: errors-ext
-version: 0.4
+version: 0.4.1
synopsis: `bracket`-like functions for `ExceptT` over `IO` monad.
description: `bracket`-like functions for `ExceptT` over `IO` monad.
homepage: https://github.com/A1-Triard/errors-ext#readme
diff --git a/src/Control/Error/Extensions.hs b/src/Control/Error/Extensions.hs
index 036f0a9..de99335 100644
--- a/src/Control/Error/Extensions.hs
+++ b/src/Control/Error/Extensions.hs
@@ -14,7 +14,7 @@
-- limitations under the License.
--
--- | This module exports 'bracket'-like functions for 'ExceptT'.
+-- | This module exports 'bracket'-like functions for @'Control.Monad.Trans.Except.ExceptT' e 'IO'@.
module Control.Error.Extensions
( bracketE
@@ -32,18 +32,23 @@ import Control.Monad.Trans.Except ()
liftedBracketOnError :: MonadBaseControl IO m => m a -> (a -> m b) -> (a -> m c) -> m c
liftedBracketOnError acquire release action = control $ \run ->
bracketOnError (run acquire) (\saved -> run (restoreM saved >>= release)) (\saved -> run (restoreM saved >>= action))
+{-# INLINE liftedBracketOnError #-}
liftedHandleAll :: MonadBaseControl IO m => (SomeException -> m a) -> m a -> m a
liftedHandleAll handler action = control $ \run ->
handleAll (run . handler) (run action)
+{-# INLINE liftedHandleAll #-}
runErrorM :: MonadError e m => m a -> m (Either e a)
runErrorM a = catchError (Right <$> a) (return . Left)
+{-# INLINE runErrorM #-}
errorM :: MonadError e m => m (Either e a) -> m a
errorM = (either throwError return =<<)
+{-# INLINE errorM #-}
--- | Analogous to 'bracket', but for @'ExceptT' e 'IO'@ (or any 'MonadError' allowing 'bracket' lifting).
+-- | Analogous to 'bracket', but for @'Control.Monad.Trans.Except.ExceptT' e 'IO'@
+-- (or any 'MonadError' allowing 'bracket' lifting).
bracketE :: (MonadBaseControl IO m, MonadError e m) => m a -> (a -> m b) -> (a -> m c) -> m c
bracketE acquire release action = errorM $ do
resource <- runErrorM acquire