
3 Nov
2011
3 Nov
'11
4:30 p.m.
On Thu, 03 Nov 2011 16:07:01 +0000, Hugo Ferreira
Hello,
Apologies the simpleton question but I would like to know how it is done in Haskell. I have a list of values, and I am applying a function to each of these elements. The result is a Maybe. I would like to return the first occurrence which is not a Nothing.
You can use catMaybes from Data.Maybe: import Data.Maybe selectOne f = head . catMaybes . map f Note that is a partial function; it will crash if f returns Nothing for each element. Cheers, Daniel