On 12/6/07, Ryan Ingram <ryani.spam@gmail.com> wrote:
On 12/6/07, Luke Palmer <lrpalmer@gmail.com > wrote:
I have actually seen this pattern a lot recently.  Recently I have
started using a function:

mergeMaybes :: (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
mergeMaybes f Nothing y = y
mergeMaybes f x Nothing = x
mergeMaybes f (Just x) (Just y) = Just (f x y)
 
mergeMaybes = liftM2 -- from Control.Monad
 
Oh wait, not quite.  Didn't realize you were returning the intermediate values in the "not nothing" case.
 
mergeMaybes f x y = liftM2 f `mplus` x `mplus` y