Skip to content

Commit 0ab63f0

Browse files
authored
add MonadThrow MonadError instances for Effect
1 parent df83c46 commit 0ab63f0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Control/Monad/Error/Class.purs

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

77
import Data.Maybe (Maybe(..))
88
import Data.Either (Either(..), either)
9+
import Effect (Effect)
10+
import Effect as Effect
11+
import Effect.Exception (Error)
12+
913

1014
-- | The `MonadThrow` type class represents those monads which support errors via
1115
-- | `throwError`, where `throwError e` halts, yielding the error `e`.
@@ -76,6 +80,13 @@ instance monadThrowMaybe :: MonadThrow Unit Maybe where
7680
instance monadErrorMaybe :: MonadError Unit Maybe where
7781
catchError Nothing f = f unit
7882
catchError (Just a) _ = Just a
83+
84+
instance monadThrowEffect :: MonadThrow Error Effect where
85+
throwError = Effect.throwException
86+
87+
instance monadErrorEffect :: MonadError Error Effect where
88+
catchError = flip Effect.catchException
89+
7990

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

0 commit comments

Comments
 (0)