Many functions can be generalised

Lana Black lanablack at amok.cc
Sun Nov 27 17:08:17 UTC 2016


On 07:10 Sun 27 Nov     , Baldur Blöndal wrote:
> > catMaybes :: (Foldable f)             => f (Maybe a) -> [a]
> > catMaybes :: (Foldable f, Foldable g) => f (g     a) -> [a]
> > catMaybes = foldMap toList
> 
> > mapMaybes ::               (a -> Maybe b) -> (forall f. Foldable f => f a
> -> [b])
> > mapMaybes :: Foldable m => (a -> m     b) -> (forall f. Foldable f => f a
> -> [b])
> > mapMaybes f = foldMap (toList . f)

These two as well as 'filter' are generalized in witherable[1].

[1]: https://hackage.haskell.org/package/witherable/


More information about the Libraries mailing list