Say we&#39;ve got these types<div><br></div><div>lst :: m [a]</div><div>getMB :: a -&gt; m (Maybe b)</div><div>getC :: b -&gt; m c</div><div><br></div><div>and we want to map getMB and getC over the elements of lst, all the while discarding elements x where getMB x == Nothing.</div>

<div><br></div><div>(This could be generalized more by replacing Maybe with some monad m&#39;, but let&#39;s run with Maybe because it&#39;s easy to talk about.)</div><div><br></div><div>The best I&#39;ve got (after some help on IRC) is this not-so-easy-to-read oneliner:</div>

<div><br></div><div>lst &gt;&gt;= (\x -&gt; mapM (liftM (liftM getC) (getMB x)) &gt;&gt;= sequence . catMaybes</div><div><br></div><div>This is hard to read, but it&#39;s also bad because we run sequence twice (once inside of mapM). If we want to do multiple things to each element of lst, it would be nice to process each element completely before moving on to the next.</div>

<div><br></div><div>Thoughts?</div><div><br></div><div>Best,<br><div>Mike S Craig<br>(908) 328 8030<br>
</div></div>