File tree 2 files changed +11
-1
lines changed 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ Notable changes to this project are documented in this file. The format is based
7
7
Breaking changes:
8
8
9
9
New features:
10
+ - Add ` liftMaybe ` and ` liftEither ` to easily lift ` Maybe ` and ` Either ` values
11
+ to a ` MonadThrow ` monad.
10
12
11
13
Bugfixes:
12
14
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ module Control.Monad.Error.Class where
4
4
5
5
import Prelude
6
6
7
- import Data.Maybe (Maybe (..))
8
7
import Data.Either (Either (..), either )
8
+ import Data.Maybe (Maybe (..), maybe )
9
9
import Effect (Effect )
10
10
import Effect.Exception as Ex
11
11
@@ -102,3 +102,11 @@ withResource acquire release kleisli = do
102
102
result <- try $ kleisli resource
103
103
release resource
104
104
either throwError pure result
105
+
106
+ -- | Lift a `Maybe` value to a MonadThrow monad.
107
+ liftMaybe :: forall m e a . MonadThrow e m => e -> Maybe a -> m a
108
+ liftMaybe error = maybe (throwError error) pure
109
+
110
+ -- | Lift an `Either` value to a MonadThrow monad.
111
+ liftEither :: forall m e a . MonadThrow e m => Either e a -> m a
112
+ liftEither = either throwError pure
You can’t perform that action at this time.
0 commit comments