[Haskell-beginners] Searching Maybe lists
Antoine Latter
aslatter at gmail.com
Mon May 18 23:23:44 EDT 2009
On Mon, May 18, 2009 at 9:56 PM, aditya siram <aditya.siram at gmail.com> wrote:
> Hi all,
> I would like to define a function that takes a list and a function that
> evaluates each member of the list to a Maybe value and output the first
> element in the list that evaluates to 'Just y', or 'Nothing' once the list
> has been completely processed. So something like:
>
> findMaybe :: [a] -> (a -> Maybe b) -> Maybe b
>
There are a couple of ways, the first one I could think of was:
> findMaybe xs f = mconcat $ map f xs
where mconcat is found in Data.Monoid
Antoine
More information about the Beginners
mailing list