File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
Expand file tree Collapse file tree 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
77Breaking changes:
88
99New features:
10+ - Add ` liftMaybe ` and ` liftEither ` to easily lift ` Maybe ` and ` Either ` values
11+ to a ` MonadThrow ` monad.
1012
1113Bugfixes:
1214
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ module Control.Monad.Error.Class where
44
55import Prelude
66
7- import Data.Maybe (Maybe (..))
87import Data.Either (Either (..), either )
8+ import Data.Maybe (Maybe (..), maybe )
99import Effect (Effect )
1010import Effect.Exception as Ex
1111
@@ -102,3 +102,11 @@ withResource acquire release kleisli = do
102102 result <- try $ kleisli resource
103103 release resource
104104 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