snoyberg / classy-prelude

A typeclass-based Prelude.
108 stars 15 forks source link

Generalize `catMaybes` #79

Closed adnelson closed 9 years ago

adnelson commented 9 years ago

catMaybes is a very useful function, and part of the ClassyPrelude. But its usefulness is somewhat limited if it's restricted to lists (it's equally useful for sets, maps, vectors, etc). I'd like to write a general catMaybes function, something like this:

catMaybes :: (IsSequence (f (Maybe a)), Functor f,
              Element (f (Maybe a)) ~ Maybe a) 
          => f (Maybe a) -> f a
catMaybes = map fromJust . filter isJust

Of course one problem here is that we can't use it on sets, because they're not functors. With a sufficiently sophisticated type signature this might be possible, though.

Anyway, would there be an interest in a function like this? If so where would be the best place to put it?

gregwebs commented 9 years ago

Looks good, we would like to have such a function in the mono-traversable package. It seems like it would be a member of the IsSequence typeclass. We aren't aiming to make everything also work on Sets.

thinkpad20 commented 9 years ago

With mono-traversable updated, should we update the cabal file for classy-prelude? Speaking of which, I'm not sure if I should have bumped the cabal version number for that package...

snoyberg commented 9 years ago

I'll bump the version in mono-traversable, don't worry.

What's the purpose in updating the classy-prelude cabal file?

snoyberg commented 9 years ago

Never mind, now I see the problem. I'm releasing 0.9.5 right now.

Can this issue be closed then?

adnelson commented 9 years ago

Yes, thanks! :)