-
Notifications
You must be signed in to change notification settings - Fork 90
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
Feature request: mapMaybe #366
Comments
@GregorySchwartz: What is the type signature that you expect for this utility? |
|
Does this do what you want?
|
It seems like this doesn't have to be example :: MonadPlus m => (a -> Maybe b) -> m a -> m b
example f m = do
a <- m
case f a of
Nothing -> mzero
Just b -> return b I'm actually surprised that there's not already something like this in |
Wouldn't the more general function be the following ? example2 :: MonadPlus m => m (Maybe a) -> m a
example2 m = do
a <- m
case a of
Nothing -> mzero
Just b -> return b Then |
Yes, that would be perfect (although simplier than I thought it would be, which is always a good thing!). |
@GregorySchwartz: Could you try to see if this could be added to |
This exists as the mapMaybe :: (Foldable f, Alterative f) => (a -> Maybe b) -> f a -> f b
mapMaybe f =
foldr (\x xs -> case p x of {Just a -> pure a <|> xs; _ -> xs}) empty |
I find myself doing
fromJust . filter isJust . fmap f
, wheref :: a -> Maybe b
. Is it possible to have amapMaybe
-like function for this to avoid importing and using partial functions?The text was updated successfully, but these errors were encountered: