On Wed, Feb 17, 2016 at 2:02 AM, M Farkas-Dyck <m.farkasdyck@gmail.com> wrote:
I quietly posted this library to Hackage nearly a year ago, but lately
learned that some seeking such a package had difficulty finding it, so
i announce it now ☺

https://hackage.haskell.org/package/filtrable

class Functor f => Filtrable f where
    mapMaybe :: (a -> Maybe b) -> f a -> f b
    catMaybes :: f (Maybe a) -> f a
    filter :: (a -> Bool) -> f a -> f a

For laws, see docs on Hackage.

This is something I’ve made for myself once or twice (I called it “Siftable”).

One law I didn’t notice you mention is:

mapMaybe f . mapMaybe g = mapMaybe (f <=< g)

In other words, mapMaybe is a functor from the Kleisli category over Maybe to Hask. (This may come free from parametricity and mapMaybe Just = id.)


--