mtl icon indicating copy to clipboard operation
mtl copied to clipboard

Added `liftMaybe` for lifting Maybe into MonadError

Open emlautarom1 opened this issue 2 years ago • 12 comments

On #37 it was discussed the existence of liftMaybe:

    I think `lift` is fine, but would also like `liftMaybe`.

Originally posted by @ocharles in https://github.com/haskell/mtl/issues/37#issuecomment-325640686

This PR adds liftMaybe, also called note in some custom preludes like Universum and Protolude

On Universum, they suggest using maybeToRight, which involves liftMaybe e = liftEither . maybeToRight e. Personally, I'm not a big fan of such boilerplate.


Lifts a Maybe into any MonadError e, using a supplied e as the error if the Maybe is Nothing.

do { val <- liftMaybe e =<< action1; action2 }

where action1 returns a Maybe.

emlautarom1 avatar Dec 15 '22 16:12 emlautarom1