Here&#39;s how I&#39;d do it:<div><br></div><div><div>import Data.Maybe (catMaybes)</div><div><br></div><div>list = [&quot;hi&quot;, &quot;blah&quot;, &quot;foo&quot;]</div><div><br></div><div>firstJust = head . catMaybes</div>
<div><br></div><div>selectOne f = firstJust . map f</div><div><br></div><div>myFunction :: String -&gt; Maybe Int</div><div>myFunction = undefined</div><div><br></div><div>main = print $ selectOne myFunction list</div><div>
<br></div><div>catMaybes will take a list of Maybe a and reduce it to a list of a, throwing out all the Nothings.</div><div><br></div><div>As you&#39;ll learn from working with Maybe a lot, if you&#39;re casing off of a maybe value, there&#39;s probably a better way to do it. Functions like &quot;catMaybes&quot; and &quot;maybe&quot; and especially the Monad instance of Maybe are really helpful for avoiding this ugly branching logic.</div>
<div><br></div><div><div class="gmail_quote">On Thu, Nov 3, 2011 at 9:07 AM, Hugo Ferreira <span dir="ltr">&lt;<a href="mailto:hmf@inescporto.pt">hmf@inescporto.pt</a>&gt;</span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br>
I am considering something like:<br>
<br>
selectOne f = take 1 . filter (\e -&gt; case e of<br>
                                       Just _ -&gt; True<br>
                                       _ -&gt; False ) . map f<br></blockquote></div><br clear="all"><div><br></div>-- <br>Michael Xavier<br><a href="http://www.michaelxavier.net" target="_blank">http://www.michaelxavier.net</a><div>
<a href="http://www.linkedin.com/pub/michael-xavier/13/b02/a26" target="_blank">LinkedIn</a></div><br>
</div></div>