-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added liftMaybe
for lifting Maybe into MonadError
#137
base: master
Are you sure you want to change the base?
Conversation
While I did say |
Note (no pun intended) that example = do
a <- liftEither $ maybeToRight "Error 1" $ ...
b <- liftEither $ maybeToRight "Error 2" $ ...
c <- liftEither $ maybeToRight "Error 3" $ ...
return () with example = do
a <- liftMaybe "Error 1" $ ...
b <- liftMaybe "Error 2" $ ...
c <- liftMaybe "Error 3" $ ...
return () |
I'm not saying use note :: MonadError e m => e -> Maybe a -> m a |
I'm actually not opposed to this, since I often find myself swallowing useless error messages and committing wholesale to algebraic blindness (vis. boolean blindness) in a bunch of important use-cases. This is one of those things that we reinvent over and over and would be good to include in |
Also in favour. Would be nice to |
@kozross I'd be in favor of waiting until the next major version bump due to the fact that |
There are multiple
As discussed, naming might not be the best and something like |
For me it seems like
I think that's very weak argument: most of the users will search this function by it's signature and the naming doesn't matter in this stage. Looking at the code, I think, it should be obvious enough what this function does, even if you haven't seen it before. |
If it's obvious what the function does, and users search by type, then the same argument applies to changing the name of the thing to |
I think that the current state of ecosystem is much more important argument though: suppose you use both mtl and monad-extras: then you have two functions with the same name with different behavior. If you use errors too, than you have two different functions that do the same. All this can be solved by using hiding/qualified imports, but I don't see any reason for such inconveniences here |
I agree with @emilypi here. |
I don't have strong opinions, but I'll drive by and point out that this is one of the instantiations of |
On #37 it was discussed the existence of
liftMaybe
:Originally posted by @ocharles in #37 (comment)
This PR adds
liftMaybe
, also callednote
in some custom preludes like Universum and ProtoludeOn Universum, they suggest using
maybeToRight
, which involvesliftMaybe e = liftEither . maybeToRight e
. Personally, I'm not a big fan of such boilerplate.Lifts a
Maybe
into anyMonadError e
, using a suppliede
as the error if theMaybe
isNothing
.where
action1
returns aMaybe
.