[Haskell-cafe] A function for Maybes

John Ky newhoggy at gmail.com
Thu Jan 25 09:15:49 EST 2007


Is there a built-in function that already does this?

foo :: (a -> b) -> Maybe a -> Maybe b
foo f m
  | isNothing m = Nothing
  | otherwise = Just (f (fromJust m))

*Main> foo (+2) (Just 3)
Just 5
*Main> foo (+2) Nothing
Nothing

If so what is it?

If not, what should I call it?

Thanks

-John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070126/a610a45e/attachment.htm


More information about the Haskell-Cafe mailing list