Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell - filter typeclass

Is there a typeclass which abstracts the filter function?

I am thinking about something like

class Filterable t where
  filter :: (a -> Bool) -> t a -> t a

If this isn't the case, is there an explicit reason for it?

like image 514
marcosh Avatar asked Feb 13 '19 09:02

marcosh


2 Answers

Yes, the witherable package provides Filterable, with a handful of instances for common types.

like image 76
Daniel Wagner Avatar answered Sep 20 '22 02:09

Daniel Wagner


There is mfilter method in Control.Monad (link)

mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a 
like image 38
talex Avatar answered Sep 23 '22 02:09

talex