<div><span class="gmail_quote">On 12/6/07, <b class="gmail_sendername">Ryan Ingram</b> <<a href="mailto:ryani.spam@gmail.com">ryani.spam@gmail.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div><span class="q"><span class="gmail_quote">On 12/6/07, <b class="gmail_sendername">Luke Palmer</b> <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:lrpalmer@gmail.com" target="_blank">lrpalmer@gmail.com
</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">I have actually seen this pattern a lot recently. Recently I have<br>started using a function:<br><br>mergeMaybes :: (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a
<br>mergeMaybes f Nothing y = y<br>mergeMaybes f x Nothing = x<br>mergeMaybes f (Just x) (Just y) = Just (f x y)</blockquote>
<div> </div></span>
<div>mergeMaybes = liftM2 -- from Control.Monad</div></div></blockquote>
<div> </div>
<div>Oh wait, not quite. Didn't realize you were returning the intermediate values in the "not nothing" case.</div>
<div> </div>
<div>mergeMaybes f x y = liftM2 f `mplus` x `mplus` y</div><br> </div>