[Haskell-cafe] [announcement] filtrable: class of filtrable containers

Sebastian Dröge slomo at coaxion.net
Wed Feb 17 08:59:19 UTC 2016


On Di, 2016-02-16 at 23:02 -0800, M Farkas-Dyck 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 looks very similar to the Witherable class from
https://hackage.haskell.org/package/witherable :


class Traversable t => Witherable t where
  wither :: Applicative f => (a -> f (Maybe b)) -> t a -> f (t b)
  wither f = fmap catMaybes . T.traverse f

  mapMaybe :: (a -> Maybe b) -> t a -> t b
  mapMaybe = mapMaybeOf wither

  catMaybes :: t (Maybe a) -> t a
  catMaybes = catMaybesOf wither

  filterA :: Applicative f => (a -> f Bool) -> t a -> f (t a)
  filterA = filterAOf wither

  filter :: (a -> Bool) -> t a -> t a
  filter = filterOf wither
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 949 bytes
Desc: This is a digitally signed message part
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160217/e035faed/attachment.sig>


More information about the Haskell-Cafe mailing list