packages feed

oops 0.1.5.0 → 0.1.6.0

raw patch · 2 files changed

+28/−3 lines, 2 filesdep +exceptions

Dependencies added: exceptions

Files

oops.cabal view
@@ -1,7 +1,7 @@ cabal-version: 3.0  name:                   oops-version:                0.1.5.0+version:                0.1.6.0 synopsis:               Combinators for handling errors of many types in a composable way description:            Combinators for handling errors of many types in a composable way. homepage:               https://www.github.com/haskell-works/oops@@ -26,6 +26,7 @@ common doctest                        { build-depends: doctest                        >= 0.16.2     && < 0.21   } common doctest-discover               { build-depends: doctest-discover               >= 0.2        && < 0.3    } common doctest-prop                   { build-depends: doctest-prop                   >= 0.2.0.1    && < 0.3    }+common exceptions                     { build-depends: exceptions                                               } common hedgehog-quickcheck            { build-depends: hedgehog-quickcheck                                      } common hedgehog                       { build-depends: hedgehog                                                 } common hspec                          { build-depends: hspec                                                    }@@ -42,6 +43,7 @@  library   import:               base, project-config,+                        exceptions,                         mtl,                         QuickCheck,                         transformers,
src/Control/Monad/Oops.hs view
@@ -52,6 +52,9 @@     recoverM,     recoverOrVoidM, +    onExceptionThrowM,+    onExceptionM,+     DV.CouldBeF (..),     DV.CouldBe  (..),     DV.CouldBeAnyOfF,@@ -71,8 +74,9 @@ import Data.Variant (Catch, CatchF(..), CouldBe, CouldBeF(..), Variant, VariantF, preposterous) import Data.Void (Void, absurd) -import qualified Data.Variant as DV-import qualified System.Exit  as IO+import qualified Control.Monad.Catch as CMC+import qualified Data.Variant        as DV+import qualified System.Exit         as IO  -- | When working in some monadic context, using 'catch' becomes trickier. The -- intuitive behaviour is that each 'catch' shrinks the variant in the left@@ -292,3 +296,22 @@   => ExceptT (Variant (x : e)) m Void   -> ExceptT (Variant e) m x recoverOrVoidM f = either pure absurd =<< (fmap Right f & catchM @x (pure . Left))++-- | Catch an exception of the specified type 'x' and throw it as an error+onExceptionThrowM :: forall x e m a. ()+  => CMC.MonadCatch m+  => CMC.Exception x+  => MonadError (Variant e) m+  => CouldBeF e x+  => m a+  -> m a+onExceptionThrowM = onExceptionM @x throwM++-- | Catch an exception of the specified type 'x' and call the the handler 'h'+onExceptionM :: forall x m a. ()+  => CMC.MonadCatch m+  => CMC.Exception x+  => (x -> m a)+  -> m a+  -> m a+onExceptionM h f = either h pure =<< CMC.try f