-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Generalization of filter and catMaybes -- @package witherable @version 0.1.2 -- | This module generalizes filterable containers. module Data.Witherable -- | Like traverse, but you can remove elements instead of -- updating them. -- --
-- traverse f ≡ wither (fmap Just . f) ---- -- A definition of wither must satisfy the following laws: -- --
-- t . wither f = wither (t . f) ---- -- Minimal complete definition: wither or catMaybes. The -- default definitions can be overriden for efficiency. class Traversable t => Witherable t where wither f = fmap catMaybes . traverse f catMaybes = runIdentity . wither pure filterA f = wither (\ a -> (\ b -> if b then Just a else Nothing) <$> f a) filter f = runIdentity . filterA (Identity . f) wither :: (Witherable t, Applicative f) => (a -> f (Maybe b)) -> t a -> f (t b) catMaybes :: Witherable t => t (Maybe a) -> t a filterA :: (Witherable t, Applicative f) => (a -> f Bool) -> t a -> f (t a) filter :: Witherable t => (a -> Bool) -> t a -> t a witherM :: (Witherable t, Monad m) => (a -> MaybeT m b) -> t a -> m (t b) -- | blightM is witherM with its arguments flipped. blightM :: (Monad m, Witherable t) => t a -> (a -> MaybeT m b) -> m (t b) instance Witherable Seq instance Witherable Vector instance Witherable (Const r) instance Witherable Proxy instance (Eq k, Hashable k) => Witherable (HashMap k) instance Ord k => Witherable (Map k) instance Witherable IntMap instance Witherable [] instance Monoid e => Witherable (Either e) instance Witherable Maybe