[Haskell-cafe] A function for Maybes
J. Garrett Morris
trevion at gmail.com
Thu Jan 25 09:22:56 EST 2007
fmap. e.g.:
Prelude> fmap ('c':) (Just "a")
Just "ca"
Prelude> fmap ('c':) Nothing
Nothing
Prelude>
/g
On 1/25/07, John Ky <newhoggy at gmail.com> wrote:
> 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
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>
--
It is myself I have never met, whose face is pasted on the underside of my mind.
More information about the Haskell-Cafe
mailing list