Skip to content

Instantly share code, notes, and snippets.

@pbrisbin
Created March 22, 2011 21:26
Show Gist options
  • Select an option

  • Save pbrisbin/882113 to your computer and use it in GitHub Desktop.

Select an option

Save pbrisbin/882113 to your computer and use it in GitHub Desktop.
-- | Conditionally apply the monadic f to the Maybe value when it is
-- Just and wrap the /inner/ value in Just, or return Nothing
(=<?) :: (Monad m) => (a -> m b) -> Maybe a -> m (Maybe b)
f =<? (Just a) = return . Just =<< f a
f =<? Nothing = return Nothing
-- can this not be done with some variation of liftM and fmap?
@md2perpe

Copy link
Copy Markdown

Have a peek on Monad transformers. I think that's just what you're doing.

@pbrisbin

Copy link
Copy Markdown
Author

Ah yes. Thanks for that link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment