-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | filterable traversable -- -- A stronger variant of traverse which can remove elements and -- generalised mapMaybe, catMaybes, filter @package witherable @version 0.2 module Data.Witherable -- | Like Functor, but it include Maybe effects. -- -- Formally, the class Filterable represents a functor from -- Kleisli Maybe to Hask. -- -- A definition of mapMaybe must satisfy the following laws: -- -- class Functor f => Filterable f where mapMaybe f = catMaybes . fmap f catMaybes = mapMaybe id filter f = mapMaybe $ \ a -> if f a then Just a else Nothing -- | Like mapMaybe. mapMaybe :: Filterable f => (a -> Maybe b) -> f a -> f b -- |
--   catMaybesmapMaybe id
--   
catMaybes :: Filterable f => f (Maybe a) -> f a -- |
--   filter f . filter g ≡ filter (liftA2 (&&) f g)
--   
filter :: Filterable f => (a -> Bool) -> f a -> f a -- | Like Traversable, but you can remove elements instead of -- updating them. -- -- A definition of wither must satisfy the following laws: -- -- -- -- Parametricity implies the naturality law: -- --
--   t . wither f ≡ wither (t . f)
--   
class (Traversable t, Filterable t) => Witherable t where wither f = fmap catMaybes . traverse f filterA = filterAOf wither -- |
--   traverse f ≡ wither (fmap Just . f)
--   
wither :: (Witherable t, Applicative f) => (a -> f (Maybe b)) -> t a -> f (t b) -- |
--   Compose . fmap (filterA f) . filterA g ≡ filterA (x -> Compose $ fmap (b -> (b&&) $ f x) (g x)
--   
filterA :: (Witherable t, Applicative f) => (a -> f Bool) -> t a -> f (t a) -- | A variant of wither that works on MaybeT. 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) -- | Removes duplicate elements from a list, keeping only the first -- occurrence. This is asymptotically faster than using nub from -- Data.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). hashNub :: (Witherable t, Eq a, Hashable a) => t a -> t a -- |
--   forMaybe = flip wither
--   
forMaybe :: (Witherable t, Applicative f) => t a -> (a -> f (Maybe b)) -> f (t b) -- | This type allows combinators to take a Filter specializing the -- parameter f. type FilterLike f s t a b = (a -> f (Maybe b)) -> s -> f t -- | A Filter is like a Traversal, but you can also remove -- targets. type Filter s t a b = forall f. Applicative f => FilterLike f s t a b -- | A simple FilterLike. type FilterLike' f s a = FilterLike f s s a a -- | A simple Filter. 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 -- |
--   forMaybeOfflip
--   
forMaybeOf :: FilterLike f s t a b -> s -> (a -> f (Maybe b)) -> 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 -- | filterA through a filter. 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 -- | Reconstitute a Filter from its monomorphic form. cloneFilter :: FilterLike (Peat a b) s t a b -> Filter s t a b -- | This is used to characterize and clone a Filter. Since -- FilterLike (Peat a b) s t a b is monomorphic, it can be used -- to store a filter in a container. newtype Peat a b t Peat :: (forall f. Applicative f => (a -> f (Maybe b)) -> f t) -> Peat a b t [runPeat] :: Peat a b t -> forall f. Applicative f => (a -> f (Maybe b)) -> f t instance GHC.Base.Functor (Data.Witherable.Peat a b) instance GHC.Base.Applicative (Data.Witherable.Peat a b) instance Data.Witherable.Filterable GHC.Base.Maybe instance Data.Witherable.Witherable GHC.Base.Maybe instance GHC.Base.Monoid e => Data.Witherable.Filterable (Data.Either.Either e) instance GHC.Base.Monoid e => Data.Witherable.Witherable (Data.Either.Either e) instance Data.Witherable.Filterable [] instance Data.Witherable.Witherable [] instance Data.Witherable.Filterable Data.IntMap.Base.IntMap instance Data.Witherable.Witherable Data.IntMap.Base.IntMap instance Data.Witherable.Filterable (Data.Map.Base.Map k) instance Data.Witherable.Witherable (Data.Map.Base.Map k) instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Data.Witherable.Filterable (Data.HashMap.Base.HashMap k) instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Data.Witherable.Witherable (Data.HashMap.Base.HashMap k) instance Data.Witherable.Filterable Data.Proxy.Proxy instance Data.Witherable.Witherable Data.Proxy.Proxy instance Data.Witherable.Filterable (Data.Functor.Const.Const r) instance Data.Witherable.Witherable (Data.Functor.Const.Const r) instance Data.Witherable.Filterable Data.Vector.Vector instance Data.Witherable.Witherable Data.Vector.Vector instance Data.Witherable.Filterable Data.Sequence.Seq instance Data.Witherable.Witherable Data.Sequence.Seq instance (GHC.Base.Functor f, Data.Witherable.Filterable g) => Data.Witherable.Filterable (Data.Functor.Compose.Compose f g) instance (Data.Traversable.Traversable f, Data.Witherable.Witherable g) => Data.Witherable.Witherable (Data.Functor.Compose.Compose f g) instance GHC.Base.Functor f => Data.Witherable.Filterable (Control.Monad.Trans.Maybe.MaybeT f) instance Data.Traversable.Traversable t => Data.Witherable.Witherable (Control.Monad.Trans.Maybe.MaybeT t)