Commit a4cb6516 authored by simonpj@microsoft.com's avatar simonpj@microsoft.com
Browse files

Add fmapM_maybe :: Monad m => (a -> m b) -> Maybe a -> m (Maybe b)

This function isn't used at the moment, but Max added it, and it
looks useful.
parent 58521c72
......@@ -10,6 +10,7 @@ module Maybes (
MaybeErr(..), -- Instance of Monad
failME, isSuccess,
fmapM_maybe,
orElse,
mapCatMaybes,
allMaybes,
......@@ -74,6 +75,14 @@ orElse :: Maybe a -> a -> a
Nothing `orElse` y = y
\end{code}
\begin{code}
fmapM_maybe :: Monad m => (a -> m b) -> Maybe a -> m (Maybe b)
fmapM_maybe _ Nothing = return Nothing
fmapM_maybe f (Just x) = do
x' <- f x
return $ Just x'
\end{code}
%************************************************************************
%* *
\subsection[MaybeT type]{The @MaybeT@ monad transformer}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment