polysemy-extra 0.1.6.1 → 0.1.7.0
raw patch · 3 files changed
+34/−1 lines, 3 filesdep +exceptionsdep +extraPVP ok
version bump matches the API change (PVP)
Dependencies added: exceptions, extra
API changes (from Hackage documentation)
+ Polysemy.Extra: irrefutableAbsorbThrow :: forall e r a. (Exception e, Members '[Error e] r) => (forall m. MonadThrow m => m a) -> Sem r a
Files
- ChangeLog.md +4/−0
- polysemy-extra.cabal +4/−1
- src/Polysemy/Extra.hs +26/−0
ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for polysemy-extra +## v0.1.7.0++* Add `irrefutableAbsorbThrow`.+ ## v0.1.6.0 * Inline fix for `runInputConstF`.
polysemy-extra.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: polysemy-extra-version: 0.1.6.1+version: 0.1.7.0 synopsis: Extra Input and Output functions for polysemy.. category: Polysemy author: Daniel Firth@@ -29,9 +29,12 @@ Paths_polysemy_extra hs-source-dirs: src+ ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints build-depends: base >=4.7 && <5 , containers+ , exceptions+ , extra , polysemy >=1.4.0.0 , polysemy-zoo default-language: Haskell2010
src/Polysemy/Extra.hs view
@@ -6,6 +6,7 @@ Extra convenience functions for polysemy. -}+{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE BlockArguments #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-}@@ -51,11 +52,19 @@ , reverseEffects2 , reverseEffects3 , reverseEffects4++-- * Exceptions+, irrefutableAbsorbThrow ) where import Control.Arrow+import Control.Monad+import qualified Control.Monad.Catch as C+import Control.Monad.Extra import Data.Map as Map import Polysemy+import Polysemy.ConstraintAbsorber.MonadCatch+import Polysemy.Error import Polysemy.KVStore import Polysemy.Input import Polysemy.Output@@ -316,3 +325,20 @@ reverseEffects4 :: forall e1 e2 e3 e4 r a. Sem (e1 ': e2 ': e3 ': e4 ': r) a -> Sem (e4 ': e3 ': e2 ': e1 ': r) a reverseEffects4 = rotateEffects4L >>> rotateEffects3L >>> rotateEffects2 {-# INLINE reverseEffects4 #-}++-- | Irrefutably absorb a `MonadThrow` constraint as a particular `Exception` type.+-- This is useful for translating functions that you know use only use+-- one error type. For more complicated uses of `MonadThrow` it's+-- probably best to just rewrite the function in terms of `Sem`.+-- +--+-- @since 0.1.7.0+irrefutableAbsorbThrow :: forall e r a. (Exception e, Members '[Error e] r)+ => (forall m. C.MonadThrow m => m a)+ -> Sem r a+irrefutableAbsorbThrow f = do+ k <- runError (absorbMonadThrow f)+ either (p >=> throw @e) return k+ where p x = fromMaybeM+ (error $ "Irrefutable Cast: " <> show x)+ (return $ C.fromException x)