1 | module Data.Filterable
5 | interface (Functor t) => Filterable t where
7 | mapMaybe : (a -> Maybe b) -> t a -> t b
8 | mapMaybe f = catMaybes . map f
10 | catMaybes : t (Maybe a) -> t a
11 | catMaybes = mapMaybe id
13 | filter : (a -> Bool) -> t a -> t a
14 | filter f = catMaybes . map g where
16 | g x = if f x then Just x else Nothing
19 | flush = mapMaybe (const Nothing)
23 | Filterable Maybe where
27 | Filterable List where
28 | mapMaybe = Prelude.List.mapMaybe