[Haskell-beginners] Selecting single result of function application to list

Hugo Ferreira hmf at inescporto.pt
Fri Nov 4 09:05:30 CET 2011


Thanks to Daniel Fischer, Daniel Schoepe and
Markus Lall for the answers.

Will have to look this over more carefully.

Rgds,
Hugo F.


On 11/03/2011 05:27 PM, Markus Läll wrote:
> There's also newtype First wraping a Maybe in Data.Monoid, in which
> you can wrap your Maybes, mconcat them and get the first Just value.
> Like:
>
>> mconcat $ map First [Nothing, Just "first", Nohing, Just "last", Nothing]
> First {getFirst = Just "first"}
>
>
> On Thu, Nov 3, 2011 at 6:07 PM, Hugo Ferreira<hmf at inescporto.pt>  wrote:
>> 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.
>>
>> I am considering something like:
>>
>> selectOne f = take 1 . filter (\e ->  case e of
>>                                        Just _ ->  True
>>                                        _ ->  False ) . map f
>>
>> I this how it is done?
>>
>> TIA,
>> Hugo F.
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
>




More information about the Beginners mailing list