Skip to content

Commit 961f403

Browse files
authored
Merge pull request #112 from safareli/patch-1
add MonadThrow MonadError instances for Effect
2 parents df83c46 + 5bd4bda commit 961f403

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

bower.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"purescript-control": "^4.0.0",
2727
"purescript-distributive": "^4.0.0",
2828
"purescript-effect": "^2.0.0",
29+
"purescript-exceptions": "^4.0.0",
2930
"purescript-either": "^4.0.0",
3031
"purescript-foldable-traversable": "^4.0.0",
3132
"purescript-identity": "^4.0.0",

src/Control/Monad/Error/Class.purs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import Prelude
66

77
import Data.Maybe (Maybe(..))
88
import Data.Either (Either(..), either)
9+
import Effect (Effect)
10+
import Effect.Exception as Ex
11+
912

1013
-- | The `MonadThrow` type class represents those monads which support errors via
1114
-- | `throwError`, where `throwError e` halts, yielding the error `e`.
@@ -76,6 +79,13 @@ instance monadThrowMaybe :: MonadThrow Unit Maybe where
7679
instance monadErrorMaybe :: MonadError Unit Maybe where
7780
catchError Nothing f = f unit
7881
catchError (Just a) _ = Just a
82+
83+
instance monadThrowEffect :: MonadThrow Ex.Error Effect where
84+
throwError = Ex.throwException
85+
86+
instance monadErrorEffect :: MonadError Ex.Error Effect where
87+
catchError = flip Ex.catchException
88+
7989

8090
-- | Make sure that a resource is cleaned up in the event of an exception. The
8191
-- | release action is called regardless of whether the body action throws or

0 commit comments

Comments
 (0)