serokell / universum

:milky_way: Prelude written in @Serokell
MIT License
176 stars 26 forks source link

Remove `listToMaybe` #206

Closed Martoon-00 closed 2 years ago

Martoon-00 commented 5 years ago

It was funny to learn that we have yet another head here which is called listToMaybe.

I think this function isn't worth living as soon as its exact behavior is not totally clear from its name (what happens if a list has more than one element?)

dcastro commented 2 years ago

Agreed, but listToMaybe's type isn't exactly the same as head though...

Maybe we should rename listToMaybe to headMaybe?

Martoon-00 commented 2 years ago

Ah, I rather compared listToMaybe to the entire family of head-like functions that we export (but my sentence was misleading).

Additionally to the functions you mentioned, there is safeHead :: Container t => t -> Maybe (Element a) that covers listToMaybe.


Maybe it's really worth having a renamed concrete headMaybe, this will solve the issue with uncertainty "what happens if the list las more than one element".

I personally think that having even 3 head-like functions is already almost too much, and we better go without [a] -> Maybe a variation.

dcastro commented 2 years ago

there is safeHead

Ah right of course! Hackage's "search box" feature wasn't being very friendly :sweat_smile:

I personally think that having even 3 head-like functions is already almost too much, and we better go without [a] -> Maybe a variation.

Absolutely, given that we have safeHead, I also vote for straight up deleting listToMaybe.