-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Generalization of filter and catMaybes -- @package witherable @version 0.1.3 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) --class Traversable t => Witherable t where wither f = fmap catMaybes . traverse f mapMaybe = mapMaybeOf wither catMaybes = catMaybesOf wither filterA = filterAOf wither filter = filterOf wither wither :: (Witherable t, Applicative f) => (a -> f (Maybe b)) -> t a -> f (t b) mapMaybe :: Witherable t => (a -> Maybe b) -> t a -> 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 -- | Removes duplicate elements from a list, keeping only the first -- occurrence. This is exponentially quicker than using nub from -- List. ordNub :: (Witherable t, Ord a) => t a -> t a -- | Removes duplicate elements from a list, keeping only the first -- occurrence. This is usually faster than ordNub, especially for -- things that have a slow comparion (like String) hashNubOf :: -- (Witherable t, Eq a, Hashable a) => t a -> t a hashNub :: (Witherable t, Eq a, Hashable a) => t a -> t a type FilterLike f s t a b = (a -> f (Maybe b)) -> s -> f t type Filter s t a b = forall f. Applicative f => FilterLike f s t a b type FilterLike' f s a = FilterLike f s s a a type Filter' s a = forall f. Applicative f => FilterLike' f s a -- | witherOf is actually id, but left for consistency. witherOf :: FilterLike f s t a b -> (a -> f (Maybe b)) -> s -> f t -- | mapMaybe through a filter. mapMaybeOf :: FilterLike Identity s t a b -> (a -> Maybe b) -> s -> t -- | catMaybes through a filter. catMaybesOf :: FilterLike Identity s t (Maybe a) a -> s -> t filterAOf :: Functor f => FilterLike' f s a -> (a -> f Bool) -> s -> f s -- | Filter each element of a structure targeted by a Filter. filterOf :: FilterLike' Identity s a -> (a -> Bool) -> s -> s -- | Remove the duplicate elements through a filter. ordNubOf :: Ord a => FilterLike' (State (Set a)) s a -> s -> s -- | Remove the duplicate elements through a filter. It is often faster -- than ordNubOf, especially when the comparison is expensive. hashNubOf :: (Eq a, Hashable a) => FilterLike' (State (HashSet a)) s a -> s -> s cloneFilter :: FilterLike (Dungeon a b) s t a b -> Filter s t a b newtype Dungeon a b t Dungeon :: (forall f. Applicative f => (a -> f (Maybe b)) -> f t) -> Dungeon a b t runDungeon :: Dungeon a b t -> forall f. Applicative f => (a -> f (Maybe b)) -> f t -- | Traversable containers which hold Maybe are witherable. newtype Chipped t a Chipped :: t (Maybe a) -> Chipped t a getChipped :: Chipped t a -> t (Maybe a) instance Ord (t (Maybe a)) => Ord (Chipped t a) instance Eq (t (Maybe a)) => Eq (Chipped t a) instance Read (t (Maybe a)) => Read (Chipped t a) instance Show (t (Maybe a)) => Show (Chipped t a) instance Functor t => Functor (Chipped t) instance Foldable t => Foldable (Chipped t) instance Traversable t => Traversable (Chipped t) instance Traversable t => Witherable (Chipped t) instance Applicative t => Applicative (Chipped t) 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 instance Applicative (Dungeon a b) instance Functor (Dungeon a b)