mirror of
https://github.com/haskell-effectful/effectful.git
synced 2024-11-24 07:14:04 +03:00
Add runFailIO
This commit is contained in:
parent
5902cfe476
commit
db61b5a324
@ -2,11 +2,13 @@
|
||||
module Effectful.Fail
|
||||
( Fail(..)
|
||||
, runFail
|
||||
, runFailIO
|
||||
) where
|
||||
|
||||
import Effectful.Dispatch.Dynamic
|
||||
import Effectful.Error.Static
|
||||
import Effectful.Internal.Monad
|
||||
import Effectful.Internal.Monad (Fail(..))
|
||||
import Effectful.Monad
|
||||
|
||||
-- | Run the 'Fail' effect via 'Error'.
|
||||
runFail :: Eff (Fail : es) a -> Eff es (Either String a)
|
||||
@ -14,3 +16,8 @@ runFail = reinterpret eff $ \_ -> \case
|
||||
Fail msg -> throwError msg
|
||||
where
|
||||
eff = fmap (either (Left . snd) Right) . runError
|
||||
|
||||
-- | Run the 'Fail' effect by using the 'MonadFail' instance for 'IO'.
|
||||
runFailIO :: IOE :> es => Eff (Fail : es) a -> Eff es a
|
||||
runFailIO = interpret $ \_ -> \case
|
||||
Fail msg -> liftIO $ fail msg
|
||||
|
Loading…
Reference in New Issue
Block a user