-- 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.4.2 module Witherable -- | Like Functor, but you can remove elements instead of updating -- them. -- -- Formally, the class Filterable represents a functor from -- Kleisli Maybe to Hask. -- -- A definition of mapMaybe must satisfy the following laws: -- --
-- catMaybes ≡ mapMaybe id --catMaybes :: Filterable f => f (Maybe a) -> f a -- |
-- filter f . filter g ≡ filter (liftA2 (&&) g f) --filter :: Filterable f => (a -> Bool) -> f a -> f a -- | An infix alias for mapMaybe. The name of the operator alludes -- to <$>, and has the same fixity. (<$?>) :: Filterable f => (a -> Maybe b) -> f a -> f b infixl 4 <$?> -- | Flipped version of <$?>, the Filterable version of -- <&>. It has the same fixity as <&>. -- --
-- (<&?>) = flip mapMaybe --(<&?>) :: Filterable f => f a -> (a -> Maybe b) -> f b infixl 1 <&?> -- | An enhancement of Traversable with Filterable -- -- A definition of wither must satisfy the following laws: -- --
-- wither f = fmap catMaybes . traverse f ---- -- If not to provide better-performing implementation, it's not necessary -- to implement any one method of Witherable. For example, if a -- type constructor T already has instances of -- Traversable and Filterable, the next one line is -- sufficient to provide the Witherable T instance. -- --
-- instance Witherable T --class (Traversable t, Filterable t) => Witherable t -- | Effectful mapMaybe. -- --
-- wither (pure . f) ≡ pure . mapMaybe f --wither :: (Witherable t, Applicative f) => (a -> f (Maybe b)) -> t a -> f (t b) -- |
-- Monadic variant of wither. This may have more efficient implementation. --witherM :: (Witherable t, Monad m) => (a -> m (Maybe b)) -> t a -> m (t b) filterA :: (Witherable t, Applicative f) => (a -> f Bool) -> t a -> f (t a) witherMap :: (Witherable t, Applicative m) => (t b -> r) -> (a -> m (Maybe b)) -> t a -> m r -- | Removes duplicate elements from a list, keeping only the first -- occurrence. This is asymptotically faster than using nub from -- Data.List. -- --
-- >>> ordNub [3,2,1,3,2,1] -- [3,2,1] --ordNub :: (Witherable t, Ord a) => t a -> t a -- | The ordNubOn function behaves just like ordNub, except -- it uses a another type to determine equivalence classes. -- --
-- >>> ordNubOn fst [(True, 'x'), (False, 'y'), (True, 'z')] -- [(True,'x'),(False,'y')] --ordNubOn :: (Witherable t, Ord b) => (a -> b) -> 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 comparison (like String). -- --
-- >>> hashNub [3,2,1,3,2,1] -- [3,2,1] --hashNub :: (Witherable t, Eq a, Hashable a) => t a -> t a -- | The hashNubOn function behaves just like ordNub, except -- it uses a another type to determine equivalence classes. -- --
-- >>> hashNubOn fst [(True, 'x'), (False, 'y'), (True, 'z')] -- [(True,'x'),(False,'y')] --hashNubOn :: (Witherable t, Eq b, Hashable b) => (a -> b) -> t a -> t a -- |
-- forMaybe = flip wither --forMaybe :: (Witherable t, Applicative f) => t a -> (a -> f (Maybe b)) -> f (t b) -- | Indexed variant of Filterable. class (FunctorWithIndex i t, Filterable t) => FilterableWithIndex i t | t -> i imapMaybe :: FilterableWithIndex i t => (i -> a -> Maybe b) -> t a -> t b -- |
-- ifilter f . ifilter g ≡ ifilter (i -> liftA2 (&&) (f i) (g i)) --ifilter :: FilterableWithIndex i t => (i -> a -> Bool) -> t a -> t a -- | Indexed variant of Witherable. class (TraversableWithIndex i t, Witherable t) => WitherableWithIndex i t | t -> i -- | Effectful imapMaybe. -- --
-- iwither ( i -> pure . f i) ≡ pure . imapMaybe f --iwither :: (WitherableWithIndex i t, Applicative f) => (i -> a -> f (Maybe b)) -> t a -> f (t b) -- |
-- Monadic variant of wither. This may have more efficient implementation. --iwitherM :: (WitherableWithIndex i t, Monad m) => (i -> a -> m (Maybe b)) -> t a -> m (t b) ifilterA :: (WitherableWithIndex i t, Applicative f) => (i -> a -> f Bool) -> t a -> f (t a) newtype WrappedFoldable f a WrapFilterable :: f a -> WrappedFoldable f a [unwrapFoldable] :: WrappedFoldable f a -> f a instance GHC.Base.Functor Witherable.BoolPair instance GHC.Base.Alternative f => GHC.Base.Alternative (Witherable.WrappedFoldable f) instance GHC.Base.Applicative f => GHC.Base.Applicative (Witherable.WrappedFoldable f) instance Data.Traversable.Traversable f => Data.Traversable.Traversable (Witherable.WrappedFoldable f) instance Data.Foldable.Foldable f => Data.Foldable.Foldable (Witherable.WrappedFoldable f) instance GHC.Base.Functor f => GHC.Base.Functor (Witherable.WrappedFoldable f) instance Witherable.Filterable f => Witherable.Filterable (Control.Monad.Trans.Identity.IdentityT f) instance Witherable.Filterable t => Witherable.Filterable (Data.Functor.Reverse.Reverse t) instance Witherable.Filterable t => Witherable.Filterable (Control.Applicative.Backwards.Backwards t) instance Witherable.FilterableWithIndex i f => Witherable.FilterableWithIndex i (Control.Monad.Trans.Identity.IdentityT f) instance Witherable.FilterableWithIndex i t => Witherable.FilterableWithIndex i (Data.Functor.Reverse.Reverse t) instance Witherable.FilterableWithIndex i t => Witherable.FilterableWithIndex i (Control.Applicative.Backwards.Backwards t) instance WithIndex.FunctorWithIndex i f => WithIndex.FunctorWithIndex i (Witherable.WrappedFoldable f) instance WithIndex.FoldableWithIndex i f => WithIndex.FoldableWithIndex i (Witherable.WrappedFoldable f) instance WithIndex.TraversableWithIndex i f => WithIndex.TraversableWithIndex i (Witherable.WrappedFoldable f) instance (Data.Foldable.Foldable f, GHC.Base.Alternative f) => Witherable.Filterable (Witherable.WrappedFoldable f) instance (WithIndex.FunctorWithIndex i f, WithIndex.FoldableWithIndex i f, GHC.Base.Alternative f) => Witherable.FilterableWithIndex i (Witherable.WrappedFoldable f) instance (GHC.Base.Alternative f, Data.Traversable.Traversable f) => Witherable.Witherable (Witherable.WrappedFoldable f) instance Witherable.WitherableWithIndex () GHC.Maybe.Maybe instance Witherable.WitherableWithIndex GHC.Types.Int [] instance Witherable.WitherableWithIndex GHC.Types.Int Control.Applicative.ZipList instance Witherable.WitherableWithIndex GHC.Types.Int Data.IntMap.Internal.IntMap instance Witherable.WitherableWithIndex k (Data.Map.Internal.Map k) instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Witherable.WitherableWithIndex k (Data.HashMap.Internal.HashMap k) instance Witherable.WitherableWithIndex Data.Void.Void Data.Proxy.Proxy instance Witherable.WitherableWithIndex GHC.Types.Int Data.Vector.Vector instance Witherable.WitherableWithIndex GHC.Types.Int Data.Sequence.Internal.Seq instance (WithIndex.TraversableWithIndex i f, Witherable.WitherableWithIndex j g) => Witherable.WitherableWithIndex (i, j) (Data.Functor.Compose.Compose f g) instance (Witherable.WitherableWithIndex i f, Witherable.WitherableWithIndex j g) => Witherable.WitherableWithIndex (Data.Either.Either i j) (Data.Functor.Product.Product f g) instance (Witherable.WitherableWithIndex i f, Witherable.WitherableWithIndex j g) => Witherable.WitherableWithIndex (Data.Either.Either i j) (Data.Functor.Sum.Sum f g) instance Witherable.WitherableWithIndex i f => Witherable.WitherableWithIndex i (Control.Monad.Trans.Identity.IdentityT f) instance Witherable.WitherableWithIndex i t => Witherable.WitherableWithIndex i (Data.Functor.Reverse.Reverse t) instance Witherable.WitherableWithIndex i t => Witherable.WitherableWithIndex i (Control.Applicative.Backwards.Backwards t) instance Witherable.FilterableWithIndex () GHC.Maybe.Maybe instance Witherable.FilterableWithIndex GHC.Types.Int [] instance Witherable.FilterableWithIndex GHC.Types.Int Control.Applicative.ZipList instance Witherable.FilterableWithIndex GHC.Types.Int Data.IntMap.Internal.IntMap instance Witherable.FilterableWithIndex k (Data.Map.Internal.Map k) instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Witherable.FilterableWithIndex k (Data.HashMap.Internal.HashMap k) instance Witherable.FilterableWithIndex Data.Void.Void Data.Proxy.Proxy instance Witherable.FilterableWithIndex GHC.Types.Int Data.Vector.Vector instance Witherable.FilterableWithIndex GHC.Types.Int Data.Sequence.Internal.Seq instance (WithIndex.FunctorWithIndex i f, Witherable.FilterableWithIndex j g) => Witherable.FilterableWithIndex (i, j) (Data.Functor.Compose.Compose f g) instance (Witherable.FilterableWithIndex i f, Witherable.FilterableWithIndex j g) => Witherable.FilterableWithIndex (Data.Either.Either i j) (Data.Functor.Product.Product f g) instance (Witherable.FilterableWithIndex i f, Witherable.FilterableWithIndex j g) => Witherable.FilterableWithIndex (Data.Either.Either i j) (Data.Functor.Sum.Sum f g) instance Witherable.Witherable GHC.Maybe.Maybe instance Witherable.Witherable Data.Semigroup.Option instance GHC.Base.Monoid e => Witherable.Witherable (Data.Either.Either e) instance Witherable.Witherable [] instance Witherable.Witherable Control.Applicative.ZipList instance Witherable.Witherable Data.IntMap.Internal.IntMap instance Witherable.Witherable (Data.Map.Internal.Map k) instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Witherable.Witherable (Data.HashMap.Internal.HashMap k) instance Witherable.Witherable Data.Proxy.Proxy instance Witherable.Witherable (Data.Functor.Const.Const r) instance Witherable.Witherable Data.Vector.Vector instance Witherable.Witherable Data.Sequence.Internal.Seq instance (Data.Traversable.Traversable f, Witherable.Witherable g) => Witherable.Witherable (Data.Functor.Compose.Compose f g) instance (Witherable.Witherable f, Witherable.Witherable g) => Witherable.Witherable (Data.Functor.Product.Product f g) instance (Witherable.Witherable f, Witherable.Witherable g) => Witherable.Witherable (Data.Functor.Sum.Sum f g) instance Witherable.Witherable f => Witherable.Witherable (Control.Monad.Trans.Identity.IdentityT f) instance Data.Traversable.Traversable t => Witherable.Witherable (Control.Monad.Trans.Maybe.MaybeT t) instance Witherable.Witherable t => Witherable.Witherable (Data.Functor.Reverse.Reverse t) instance Witherable.Witherable t => Witherable.Witherable (Control.Applicative.Backwards.Backwards t) instance Witherable.Witherable GHC.Generics.V1 instance Witherable.Witherable GHC.Generics.U1 instance Witherable.Witherable (GHC.Generics.K1 i c) instance Witherable.Witherable f => Witherable.Witherable (GHC.Generics.Rec1 f) instance Witherable.Witherable f => Witherable.Witherable (GHC.Generics.M1 i c f) instance (Witherable.Witherable f, Witherable.Witherable g) => Witherable.Witherable (f GHC.Generics.:*: g) instance (Witherable.Witherable f, Witherable.Witherable g) => Witherable.Witherable (f GHC.Generics.:+: g) instance (Data.Traversable.Traversable f, Witherable.Witherable g) => Witherable.Witherable (f GHC.Generics.:.: g) instance Witherable.Filterable GHC.Maybe.Maybe instance Witherable.Filterable Data.Semigroup.Option instance GHC.Base.Monoid e => Witherable.Filterable (Data.Either.Either e) instance Witherable.Filterable [] instance Witherable.Filterable Control.Applicative.ZipList instance Witherable.Filterable Data.IntMap.Internal.IntMap instance Witherable.Filterable (Data.Map.Internal.Map k) instance (GHC.Classes.Eq k, Data.Hashable.Class.Hashable k) => Witherable.Filterable (Data.HashMap.Internal.HashMap k) instance Witherable.Filterable Data.Proxy.Proxy instance Witherable.Filterable (Data.Functor.Const.Const r) instance Witherable.Filterable Data.Vector.Vector instance Witherable.Filterable Data.Sequence.Internal.Seq instance (GHC.Base.Functor f, Witherable.Filterable g) => Witherable.Filterable (Data.Functor.Compose.Compose f g) instance (Witherable.Filterable f, Witherable.Filterable g) => Witherable.Filterable (Data.Functor.Product.Product f g) instance (Witherable.Filterable f, Witherable.Filterable g) => Witherable.Filterable (Data.Functor.Sum.Sum f g) instance GHC.Base.Functor f => Witherable.Filterable (Control.Monad.Trans.Maybe.MaybeT f) instance Witherable.Filterable GHC.Generics.V1 instance Witherable.Filterable GHC.Generics.U1 instance Witherable.Filterable (GHC.Generics.K1 i c) instance Witherable.Filterable f => Witherable.Filterable (GHC.Generics.Rec1 f) instance Witherable.Filterable f => Witherable.Filterable (GHC.Generics.M1 i c f) instance (Witherable.Filterable f, Witherable.Filterable g) => Witherable.Filterable (f GHC.Generics.:*: g) instance (Witherable.Filterable f, Witherable.Filterable g) => Witherable.Filterable (f GHC.Generics.:+: g) instance (GHC.Base.Functor f, Witherable.Filterable g) => Witherable.Filterable (f GHC.Generics.:.: g) -- | Deprecated: Use Witherable instead module Data.Witherable -- | Like Functor, but you can remove elements instead of updating -- them. -- -- Formally, the class Filterable represents a functor from -- Kleisli Maybe to Hask. -- -- A definition of mapMaybe must satisfy the following laws: -- --
-- catMaybes ≡ mapMaybe id --catMaybes :: Filterable f => f (Maybe a) -> f a -- |
-- filter f . filter g ≡ filter (liftA2 (&&) g f) --filter :: Filterable f => (a -> Bool) -> f a -> f a -- | An infix alias for mapMaybe. The name of the operator alludes -- to <$>, and has the same fixity. (<$?>) :: Filterable f => (a -> Maybe b) -> f a -> f b infixl 4 <$?> -- | Flipped version of <$?>, the Filterable version of -- <&>. It has the same fixity as <&>. -- --
-- (<&?>) = flip mapMaybe --(<&?>) :: Filterable f => f a -> (a -> Maybe b) -> f b infixl 1 <&?> -- | An enhancement of Traversable with Filterable -- -- A definition of wither must satisfy the following laws: -- --
-- wither f = fmap catMaybes . traverse f ---- -- If not to provide better-performing implementation, it's not necessary -- to implement any one method of Witherable. For example, if a -- type constructor T already has instances of -- Traversable and Filterable, the next one line is -- sufficient to provide the Witherable T instance. -- --
-- instance Witherable T --class (Traversable t, Filterable t) => Witherable t -- | Effectful mapMaybe. -- --
-- wither (pure . f) ≡ pure . mapMaybe f --wither :: (Witherable t, Applicative f) => (a -> f (Maybe b)) -> t a -> f (t b) -- |
-- Monadic variant of wither. This may have more efficient implementation. --witherM :: (Witherable t, Monad m) => (a -> m (Maybe b)) -> t a -> m (t b) filterA :: (Witherable t, Applicative f) => (a -> f Bool) -> t a -> f (t a) witherMap :: (Witherable t, Applicative m) => (t b -> r) -> (a -> m (Maybe b)) -> t a -> m r -- | Removes duplicate elements from a list, keeping only the first -- occurrence. This is asymptotically faster than using nub from -- Data.List. -- --
-- >>> ordNub [3,2,1,3,2,1] -- [3,2,1] --ordNub :: (Witherable t, Ord a) => t a -> t a -- | The ordNubOn function behaves just like ordNub, except -- it uses a another type to determine equivalence classes. -- --
-- >>> ordNubOn fst [(True, 'x'), (False, 'y'), (True, 'z')] -- [(True,'x'),(False,'y')] --ordNubOn :: (Witherable t, Ord b) => (a -> b) -> 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 comparison (like String). -- --
-- >>> hashNub [3,2,1,3,2,1] -- [3,2,1] --hashNub :: (Witherable t, Eq a, Hashable a) => t a -> t a -- | The hashNubOn function behaves just like ordNub, except -- it uses a another type to determine equivalence classes. -- --
-- >>> hashNubOn fst [(True, 'x'), (False, 'y'), (True, 'z')] -- [(True,'x'),(False,'y')] --hashNubOn :: (Witherable t, Eq b, Hashable b) => (a -> b) -> t a -> t a -- |
-- forMaybe = flip wither --forMaybe :: (Witherable t, Applicative f) => t a -> (a -> f (Maybe b)) -> f (t b) -- | Indexed variant of Filterable. class (FunctorWithIndex i t, Filterable t) => FilterableWithIndex i t | t -> i imapMaybe :: FilterableWithIndex i t => (i -> a -> Maybe b) -> t a -> t b -- |
-- ifilter f . ifilter g ≡ ifilter (i -> liftA2 (&&) (f i) (g i)) --ifilter :: FilterableWithIndex i t => (i -> a -> Bool) -> t a -> t a -- | Indexed variant of Witherable. class (TraversableWithIndex i t, Witherable t) => WitherableWithIndex i t | t -> i -- | Effectful imapMaybe. -- --
-- iwither ( i -> pure . f i) ≡ pure . imapMaybe f --iwither :: (WitherableWithIndex i t, Applicative f) => (i -> a -> f (Maybe b)) -> t a -> f (t b) -- |
-- Monadic variant of wither. This may have more efficient implementation. --iwitherM :: (WitherableWithIndex i t, Monad m) => (i -> a -> m (Maybe b)) -> t a -> m (t b) ifilterA :: (WitherableWithIndex i t, Applicative f) => (i -> a -> f Bool) -> t a -> f (t a) -- | This type allows combinators to take a Filter specializing the -- parameter f. type WitherLike f s t a b = (a -> f (Maybe b)) -> s -> f t -- | A Wither is like a Traversal, but you can also remove -- targets. type Wither s t a b = forall f. Applicative f => WitherLike f s t a b -- | A simple WitherLike. type WitherLike' f s a = WitherLike f s s a a -- | A simple Wither. type Wither' s a = forall f. Applicative f => WitherLike' f s a type FilterLike f s t a b = WitherLike f s t a b type Filter s t a b = Wither s t a b type FilterLike' f s a = WitherLike' f s a type Filter' s a = Wither' s a -- | witherOf is actually id, but left for consistency. witherOf :: FilterLike f s t a b -> (a -> f (Maybe b)) -> s -> f t -- |
-- forMaybeOf ≡ flip --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. ordNubOnOf :: Ord b => FilterLike' (State (Set b)) s a -> (a -> b) -> 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 -- | Remove the duplicate elements through a filter. hashNubOnOf :: (Eq b, Hashable b) => FilterLike' (State (HashSet b)) s a -> (a -> b) -> 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 newtype WrappedFoldable f a WrapFilterable :: f a -> WrappedFoldable f a [unwrapFoldable] :: WrappedFoldable f a -> f a instance GHC.Base.Functor (Data.Witherable.Peat a b) instance GHC.Base.Applicative (Data.Witherable.Peat a b)