Maybe perform an action

Hi Haskellers, I have another simple question in order to improve my coding style. I'm using the following function, e.g. when a dialog returned Maybe NiceStuff: performMaybe :: Monad m ⇒ Maybe a → (a → m b) → m () performMaybe x action = when (isJust x) (action (fromJust x) >> return ()) example use: main = performMaybe (Just "Hello") print Now I wonder if others use such a function as well, if it's already defined in the standard libraries (didn't find it using Hoogle) and perhaps how to implement it a little nicer. Regards Tim

On Sun, Dec 5, 2010 at 1:23 PM, Tim Baumgartner
Hi Haskellers,
I have another simple question in order to improve my coding style. I'm using the following function, e.g. when a dialog returned Maybe NiceStuff:
performMaybe :: Monad m ⇒ Maybe a → (a → m b) → m () performMaybe x action = when (isJust x) (action (fromJust x) >> return ())
example use: main = performMaybe (Just "Hello") print
Now I wonder if others use such a function as well, if it's already defined in the standard libraries (didn't find it using Hoogle) and perhaps how to implement it a little nicer.
I often times do this as maybe (return ()) If you want the exact same type signature, you just need to flip it: flip (maybe $ return ()) Michael
participants (2)
-
Michael Snoyman
-
Tim Baumgartner