Copyright | (c) Fumiaki Kinoshita 2015 |
---|---|
License | BSD3 |
Maintainer | Fumiaki Kinoshita <fumiexcel@gmail.com> |
Stability | provisional |
Portability | non-portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Deprecated: Use Witherable instead
Synopsis
- class Functor f => Filterable f where
- (<$?>) :: Filterable f => (a -> Maybe b) -> f a -> f b
- (<&?>) :: Filterable f => f a -> (a -> Maybe b) -> f b
- class (Traversable t, Filterable t) => Witherable t where
- wither :: Applicative f => (a -> f (Maybe b)) -> t a -> f (t b)
- witherM :: Monad m => (a -> m (Maybe b)) -> t a -> m (t b)
- filterA :: Applicative f => (a -> f Bool) -> t a -> f (t a)
- witherMap :: Applicative m => (t b -> r) -> (a -> m (Maybe b)) -> t a -> m r
- ordNub :: (Witherable t, Ord a) => t a -> t a
- ordNubOn :: (Witherable t, Ord b) => (a -> b) -> t a -> t a
- hashNub :: (Witherable t, Eq a, Hashable a) => t a -> t a
- hashNubOn :: (Witherable t, Eq b, Hashable b) => (a -> b) -> t a -> t a
- forMaybe :: (Witherable t, Applicative f) => t a -> (a -> f (Maybe b)) -> f (t b)
- class (FunctorWithIndex i t, Filterable t) => FilterableWithIndex i t | t -> i where
- class (TraversableWithIndex i t, Witherable t) => WitherableWithIndex i t | t -> i where
- iwither :: Applicative f => (i -> a -> f (Maybe b)) -> t a -> f (t b)
- iwitherM :: Monad m => (i -> a -> m (Maybe b)) -> t a -> m (t b)
- ifilterA :: Applicative f => (i -> a -> f Bool) -> t a -> f (t a)
- type WitherLike f s t a b = (a -> f (Maybe b)) -> s -> f t
- type Wither s t a b = forall f. Applicative f => WitherLike f s t a b
- type WitherLike' f s a = WitherLike f s s a a
- 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 :: FilterLike f s t a b -> (a -> f (Maybe b)) -> s -> f t
- forMaybeOf :: FilterLike f s t a b -> s -> (a -> f (Maybe b)) -> f t
- mapMaybeOf :: FilterLike Identity s t a b -> (a -> Maybe b) -> s -> t
- catMaybesOf :: FilterLike Identity s t (Maybe a) a -> s -> t
- filterAOf :: Functor f => FilterLike' f s a -> (a -> f Bool) -> s -> f s
- filterOf :: FilterLike' Identity s a -> (a -> Bool) -> s -> s
- ordNubOf :: Ord a => FilterLike' (State (Set a)) s a -> s -> s
- ordNubOnOf :: Ord b => FilterLike' (State (Set b)) s a -> (a -> b) -> s -> s
- hashNubOf :: (Eq a, Hashable a) => FilterLike' (State (HashSet a)) s a -> s -> s
- hashNubOnOf :: (Eq b, Hashable b) => FilterLike' (State (HashSet b)) s a -> (a -> b) -> s -> s
- cloneFilter :: FilterLike (Peat a b) s t a b -> Filter s t a b
- newtype Peat a b t = Peat {
- runPeat :: forall f. Applicative f => (a -> f (Maybe b)) -> f t
- newtype WrappedFoldable f a = WrapFilterable {
- unwrapFoldable :: f a
Documentation
class Functor f => Filterable f where Source #
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:
mapMaybe :: (a -> Maybe b) -> f a -> f b Source #
Like mapMaybe
.
Instances
(<$?>) :: Filterable f => (a -> Maybe b) -> f a -> f b infixl 4 Source #
(<&?>) :: Filterable f => f a -> (a -> Maybe b) -> f b infixl 1 Source #
class (Traversable t, Filterable t) => Witherable t where Source #
An enhancement of Traversable
with Filterable
A definition of wither
must satisfy the following laws:
- conservation
wither
(fmap
Just
. f) ≡traverse
f- composition
Compose
.fmap
(wither
f) .wither
g ≡wither
(Compose
.fmap
(wither
f) . g)
Parametricity implies the naturality law:
Whenever t
is an /applicative transformation/ in the sense described in the
Traversable
documentation,
t .wither
f ≡wither
(t . f)
See the Properties.md
file in the git distribution for some special properties of
empty containers.
Nothing
wither :: Applicative f => (a -> f (Maybe b)) -> t a -> f (t b) Source #
witherM :: Monad m => (a -> m (Maybe b)) -> t a -> m (t b) Source #
Monadic variant of wither
. This may have more efficient implementation.
filterA :: Applicative f => (a -> f Bool) -> t a -> f (t a) Source #
witherMap :: Applicative m => (t b -> r) -> (a -> m (Maybe b)) -> t a -> m r Source #
Instances
Witherable [] Source # | Methods are good consumers for fusion. |
Defined in Witherable | |
Witherable Maybe Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> Maybe a -> f (Maybe b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Maybe a -> m (Maybe b) Source # filterA :: Applicative f => (a -> f Bool) -> Maybe a -> f (Maybe a) Source # witherMap :: Applicative m => (Maybe b -> r) -> (a -> m (Maybe b)) -> Maybe a -> m r Source # | |
Witherable Option Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> Option a -> f (Option b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Option a -> m (Option b) Source # filterA :: Applicative f => (a -> f Bool) -> Option a -> f (Option a) Source # witherMap :: Applicative m => (Option b -> r) -> (a -> m (Maybe b)) -> Option a -> m r Source # | |
Witherable ZipList Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> ZipList a -> f (ZipList b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> ZipList a -> m (ZipList b) Source # filterA :: Applicative f => (a -> f Bool) -> ZipList a -> f (ZipList a) Source # witherMap :: Applicative m => (ZipList b -> r) -> (a -> m (Maybe b)) -> ZipList a -> m r Source # | |
Witherable IntMap Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> IntMap a -> f (IntMap b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> IntMap a -> m (IntMap b) Source # filterA :: Applicative f => (a -> f Bool) -> IntMap a -> f (IntMap a) Source # witherMap :: Applicative m => (IntMap b -> r) -> (a -> m (Maybe b)) -> IntMap a -> m r Source # | |
Witherable Seq Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> Seq a -> f (Seq b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Seq a -> m (Seq b) Source # filterA :: Applicative f => (a -> f Bool) -> Seq a -> f (Seq a) Source # witherMap :: Applicative m => (Seq b -> r) -> (a -> m (Maybe b)) -> Seq a -> m r Source # | |
Witherable Vector Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> Vector a -> f (Vector b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Vector a -> m (Vector b) Source # filterA :: Applicative f => (a -> f Bool) -> Vector a -> f (Vector a) Source # witherMap :: Applicative m => (Vector b -> r) -> (a -> m (Maybe b)) -> Vector a -> m r Source # | |
Monoid e => Witherable (Either e) Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> Either e a -> f (Either e b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Either e a -> m (Either e b) Source # filterA :: Applicative f => (a -> f Bool) -> Either e a -> f (Either e a) Source # witherMap :: Applicative m => (Either e b -> r) -> (a -> m (Maybe b)) -> Either e a -> m r Source # | |
Witherable (V1 :: Type -> Type) Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> V1 a -> f (V1 b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> V1 a -> m (V1 b) Source # filterA :: Applicative f => (a -> f Bool) -> V1 a -> f (V1 a) Source # witherMap :: Applicative m => (V1 b -> r) -> (a -> m (Maybe b)) -> V1 a -> m r Source # | |
Witherable (U1 :: Type -> Type) Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> U1 a -> f (U1 b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> U1 a -> m (U1 b) Source # filterA :: Applicative f => (a -> f Bool) -> U1 a -> f (U1 a) Source # witherMap :: Applicative m => (U1 b -> r) -> (a -> m (Maybe b)) -> U1 a -> m r Source # | |
Witherable (Proxy :: Type -> Type) Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> Proxy a -> f (Proxy b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Proxy a -> m (Proxy b) Source # filterA :: Applicative f => (a -> f Bool) -> Proxy a -> f (Proxy a) Source # witherMap :: Applicative m => (Proxy b -> r) -> (a -> m (Maybe b)) -> Proxy a -> m r Source # | |
Witherable (Map k) Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> Map k a -> f (Map k b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Map k a -> m (Map k b) Source # filterA :: Applicative f => (a -> f Bool) -> Map k a -> f (Map k a) Source # witherMap :: Applicative m => (Map k b -> r) -> (a -> m (Maybe b)) -> Map k a -> m r Source # | |
Traversable t => Witherable (MaybeT t) Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> MaybeT t a -> f (MaybeT t b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> MaybeT t a -> m (MaybeT t b) Source # filterA :: Applicative f => (a -> f Bool) -> MaybeT t a -> f (MaybeT t a) Source # witherMap :: Applicative m => (MaybeT t b -> r) -> (a -> m (Maybe b)) -> MaybeT t a -> m r Source # | |
(Eq k, Hashable k) => Witherable (HashMap k) Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> HashMap k a -> f (HashMap k b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> HashMap k a -> m (HashMap k b) Source # filterA :: Applicative f => (a -> f Bool) -> HashMap k a -> f (HashMap k a) Source # witherMap :: Applicative m => (HashMap k b -> r) -> (a -> m (Maybe b)) -> HashMap k a -> m r Source # | |
(Alternative f, Traversable f) => Witherable (WrappedFoldable f) Source # | |
Defined in Witherable wither :: Applicative f0 => (a -> f0 (Maybe b)) -> WrappedFoldable f a -> f0 (WrappedFoldable f b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> WrappedFoldable f a -> m (WrappedFoldable f b) Source # filterA :: Applicative f0 => (a -> f0 Bool) -> WrappedFoldable f a -> f0 (WrappedFoldable f a) Source # witherMap :: Applicative m => (WrappedFoldable f b -> r) -> (a -> m (Maybe b)) -> WrappedFoldable f a -> m r Source # | |
Witherable f => Witherable (Rec1 f) Source # | |
Defined in Witherable wither :: Applicative f0 => (a -> f0 (Maybe b)) -> Rec1 f a -> f0 (Rec1 f b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Rec1 f a -> m (Rec1 f b) Source # filterA :: Applicative f0 => (a -> f0 Bool) -> Rec1 f a -> f0 (Rec1 f a) Source # witherMap :: Applicative m => (Rec1 f b -> r) -> (a -> m (Maybe b)) -> Rec1 f a -> m r Source # | |
Witherable (Const r :: Type -> Type) Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> Const r a -> f (Const r b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Const r a -> m (Const r b) Source # filterA :: Applicative f => (a -> f Bool) -> Const r a -> f (Const r a) Source # witherMap :: Applicative m => (Const r b -> r0) -> (a -> m (Maybe b)) -> Const r a -> m r0 Source # | |
Witherable t => Witherable (Reverse t) Source # | Wither from right to left. |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> Reverse t a -> f (Reverse t b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Reverse t a -> m (Reverse t b) Source # filterA :: Applicative f => (a -> f Bool) -> Reverse t a -> f (Reverse t a) Source # witherMap :: Applicative m => (Reverse t b -> r) -> (a -> m (Maybe b)) -> Reverse t a -> m r Source # | |
Witherable f => Witherable (IdentityT f) Source # | |
Defined in Witherable wither :: Applicative f0 => (a -> f0 (Maybe b)) -> IdentityT f a -> f0 (IdentityT f b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> IdentityT f a -> m (IdentityT f b) Source # filterA :: Applicative f0 => (a -> f0 Bool) -> IdentityT f a -> f0 (IdentityT f a) Source # witherMap :: Applicative m => (IdentityT f b -> r) -> (a -> m (Maybe b)) -> IdentityT f a -> m r Source # | |
Witherable t => Witherable (Backwards t) Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> Backwards t a -> f (Backwards t b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Backwards t a -> m (Backwards t b) Source # filterA :: Applicative f => (a -> f Bool) -> Backwards t a -> f (Backwards t a) Source # witherMap :: Applicative m => (Backwards t b -> r) -> (a -> m (Maybe b)) -> Backwards t a -> m r Source # | |
Witherable (K1 i c :: Type -> Type) Source # | |
Defined in Witherable wither :: Applicative f => (a -> f (Maybe b)) -> K1 i c a -> f (K1 i c b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> K1 i c a -> m (K1 i c b) Source # filterA :: Applicative f => (a -> f Bool) -> K1 i c a -> f (K1 i c a) Source # witherMap :: Applicative m => (K1 i c b -> r) -> (a -> m (Maybe b)) -> K1 i c a -> m r Source # | |
(Witherable f, Witherable g) => Witherable (f :+: g) Source # | |
Defined in Witherable wither :: Applicative f0 => (a -> f0 (Maybe b)) -> (f :+: g) a -> f0 ((f :+: g) b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> (f :+: g) a -> m ((f :+: g) b) Source # filterA :: Applicative f0 => (a -> f0 Bool) -> (f :+: g) a -> f0 ((f :+: g) a) Source # witherMap :: Applicative m => ((f :+: g) b -> r) -> (a -> m (Maybe b)) -> (f :+: g) a -> m r Source # | |
(Witherable f, Witherable g) => Witherable (f :*: g) Source # | |
Defined in Witherable wither :: Applicative f0 => (a -> f0 (Maybe b)) -> (f :*: g) a -> f0 ((f :*: g) b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> (f :*: g) a -> m ((f :*: g) b) Source # filterA :: Applicative f0 => (a -> f0 Bool) -> (f :*: g) a -> f0 ((f :*: g) a) Source # witherMap :: Applicative m => ((f :*: g) b -> r) -> (a -> m (Maybe b)) -> (f :*: g) a -> m r Source # | |
(Witherable f, Witherable g) => Witherable (Product f g) Source # | |
Defined in Witherable wither :: Applicative f0 => (a -> f0 (Maybe b)) -> Product f g a -> f0 (Product f g b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Product f g a -> m (Product f g b) Source # filterA :: Applicative f0 => (a -> f0 Bool) -> Product f g a -> f0 (Product f g a) Source # witherMap :: Applicative m => (Product f g b -> r) -> (a -> m (Maybe b)) -> Product f g a -> m r Source # | |
(Witherable f, Witherable g) => Witherable (Sum f g) Source # | |
Defined in Witherable wither :: Applicative f0 => (a -> f0 (Maybe b)) -> Sum f g a -> f0 (Sum f g b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Sum f g a -> m (Sum f g b) Source # filterA :: Applicative f0 => (a -> f0 Bool) -> Sum f g a -> f0 (Sum f g a) Source # witherMap :: Applicative m => (Sum f g b -> r) -> (a -> m (Maybe b)) -> Sum f g a -> m r Source # | |
Witherable f => Witherable (M1 i c f) Source # | |
Defined in Witherable wither :: Applicative f0 => (a -> f0 (Maybe b)) -> M1 i c f a -> f0 (M1 i c f b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> M1 i c f a -> m (M1 i c f b) Source # filterA :: Applicative f0 => (a -> f0 Bool) -> M1 i c f a -> f0 (M1 i c f a) Source # witherMap :: Applicative m => (M1 i c f b -> r) -> (a -> m (Maybe b)) -> M1 i c f a -> m r Source # | |
(Traversable f, Witherable g) => Witherable (f :.: g) Source # | |
Defined in Witherable wither :: Applicative f0 => (a -> f0 (Maybe b)) -> (f :.: g) a -> f0 ((f :.: g) b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> (f :.: g) a -> m ((f :.: g) b) Source # filterA :: Applicative f0 => (a -> f0 Bool) -> (f :.: g) a -> f0 ((f :.: g) a) Source # witherMap :: Applicative m => ((f :.: g) b -> r) -> (a -> m (Maybe b)) -> (f :.: g) a -> m r Source # | |
(Traversable f, Witherable g) => Witherable (Compose f g) Source # | |
Defined in Witherable wither :: Applicative f0 => (a -> f0 (Maybe b)) -> Compose f g a -> f0 (Compose f g b) Source # witherM :: Monad m => (a -> m (Maybe b)) -> Compose f g a -> m (Compose f g b) Source # filterA :: Applicative f0 => (a -> f0 Bool) -> Compose f g a -> f0 (Compose f g a) Source # witherMap :: Applicative m => (Compose f g b -> r) -> (a -> m (Maybe b)) -> Compose f g a -> m r Source # |
ordNub :: (Witherable t, Ord a) => t a -> t a Source #
ordNubOn :: (Witherable t, Ord b) => (a -> b) -> t a -> t a Source #
forMaybe :: (Witherable t, Applicative f) => t a -> (a -> f (Maybe b)) -> f (t b) Source #
Indexed variants
class (FunctorWithIndex i t, Filterable t) => FilterableWithIndex i t | t -> i where Source #
Indexed variant of Filterable
.
Nothing
Instances
class (TraversableWithIndex i t, Witherable t) => WitherableWithIndex i t | t -> i where Source #
Indexed variant of Witherable
.
Nothing
iwither :: Applicative f => (i -> a -> f (Maybe b)) -> t a -> f (t b) Source #
iwitherM :: Monad m => (i -> a -> m (Maybe b)) -> t a -> m (t b) Source #
Monadic variant of wither
. This may have more efficient implementation.
ifilterA :: Applicative f => (i -> a -> f Bool) -> t a -> f (t a) Source #
Instances
Generalization
type WitherLike f s t a b = (a -> f (Maybe b)) -> s -> f t Source #
This type allows combinators to take a Filter
specializing the parameter f
.
type Wither s t a b = forall f. Applicative f => WitherLike f s t a b Source #
type WitherLike' f s a = WitherLike f s s a a Source #
A simple WitherLike
.
type Wither' s a = forall f. Applicative f => WitherLike' f s a Source #
A simple Wither
.
type FilterLike f s t a b = WitherLike f s t a b Source #
type FilterLike' f s a = WitherLike' f s a Source #
witherOf :: FilterLike f s t a b -> (a -> f (Maybe b)) -> s -> f t Source #
forMaybeOf :: FilterLike f s t a b -> s -> (a -> f (Maybe b)) -> f t Source #
mapMaybeOf :: FilterLike Identity s t a b -> (a -> Maybe b) -> s -> t Source #
mapMaybe
through a filter.
catMaybesOf :: FilterLike Identity s t (Maybe a) a -> s -> t Source #
catMaybes
through a filter.
filterAOf :: Functor f => FilterLike' f s a -> (a -> f Bool) -> s -> f s Source #
filterA
through a filter.
filterOf :: FilterLike' Identity s a -> (a -> Bool) -> s -> s Source #
Filter each element of a structure targeted by a Filter
.
ordNubOf :: Ord a => FilterLike' (State (Set a)) s a -> s -> s Source #
Remove the duplicate elements through a filter.
ordNubOnOf :: Ord b => FilterLike' (State (Set b)) s a -> (a -> b) -> s -> s Source #
Remove the duplicate elements through a filter.
hashNubOf :: (Eq a, Hashable a) => FilterLike' (State (HashSet a)) s a -> s -> s Source #
Remove the duplicate elements through a filter.
It is often faster than ordNubOf
, especially when the comparison is expensive.
hashNubOnOf :: (Eq b, Hashable b) => FilterLike' (State (HashSet b)) s a -> (a -> b) -> s -> s Source #
Remove the duplicate elements through a filter.
Cloning
cloneFilter :: FilterLike (Peat a b) s t a b -> Filter s t a b Source #
Reconstitute a Filter
from its monomorphic form.
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.
Peat | |
|
Wrapper
newtype WrappedFoldable f a Source #
WrapFilterable | |
|