Common Method for [Maybe a] -> [a]

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Common Method for [Maybe a] -> [a]

Leonhard Applis
Hey there,

I've got a method:

demaybefy :: [Maybe a] -> [a]
demaybefy [] = []
demaybefy (x:xs) = case x of
Just x -> x : demaybefy xs
Nothing -> demaybefy xs



However, i feel that there is a method from preload/list/maybe that does exactly the same, but i cannot find it.
Can someone help me?

best regards
Leonhard

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

publickey - Leonhard.Applis@protonmail.com - 0x807FDDF3.asc (2K) Download Attachment
signature.asc (523 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Common Method for [Maybe a] -> [a]

Simon Jakobi
Hi Leonhard,

the function is called catMaybes.


Cheers,
Simon

Am Mi., 1. Mai 2019 um 13:05 Uhr schrieb Leonhard Applis <[hidden email]>:
Hey there,

I've got a method:

demaybefy :: [Maybe a] -> [a]
demaybefy [] = []
demaybefy (x:xs) = case x of
Just x -> x : demaybefy xs
Nothing -> demaybefy xs



However, i feel that there is a method from preload/list/maybe that does exactly the same, but i cannot find it.
Can someone help me?

best regards
Leonhard
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Common Method for [Maybe a] -> [a]

Francesco Ariis
In reply to this post by Leonhard Applis
Hello Leonard,

On Wed, May 01, 2019 at 11:04:46AM +0000, Leonhard Applis wrote:
> I've got a method:
>
> demaybefy  :: [Maybe  a] -> [a]
> [...]
>
>
> However, i feel that there is a method from preload/list/maybe that
> does exactly the same, but i cannot find it.
> Can someone help me?

Simon already gave the right answer; never forget that for question like
this, Hoogle is phenomenal! Just write in the sought signature and voila:

    https://hoogle.haskell.org/?hoogle=%5BMaybe%20a%5D%20-%3E%20%5Ba%5D
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Common Method for [Maybe a] -> [a]

Tony Morris-4
Also in general form.

https://hackage.haskell.org/package/witherable-0.3/docs/Data-Witherable.html#v:catMaybes

On 1/5/19 10:56 pm, Francesco Ariis wrote:

> Hello Leonard,
>
> On Wed, May 01, 2019 at 11:04:46AM +0000, Leonhard Applis wrote:
>> I've got a method:
>>
>> demaybefy  :: [Maybe  a] -> [a]
>> [...]
>>
>>
>> However, i feel that there is a method from preload/list/maybe that
>> does exactly the same, but i cannot find it.
>> Can someone help me?
> Simon already gave the right answer; never forget that for question like
> this, Hoogle is phenomenal! Just write in the sought signature and voila:
>
>     https://hoogle.haskell.org/?hoogle=%5BMaybe%20a%5D%20-%3E%20%5Ba%5D
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

signature.asc (499 bytes) Download Attachment