Copyright | (c) Fumiaki Kinoshita 2015 |
---|---|
License | BSD3 |
Maintainer | Fumiaki Kinoshita <fumiexcel@gmail.com> |
Stability | provisional |
Portability | non-portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Data.Witherable
Description
- class Traversable t => Witherable t where
- witherM :: (Witherable t, Monad m) => (a -> MaybeT m b) -> t a -> m (t b)
- blightM :: (Monad m, Witherable t) => t a -> (a -> MaybeT m b) -> m (t b)
- ordNub :: (Witherable t, Ord a) => t a -> t a
- hashNub :: (Witherable t, Eq a, Hashable a) => t a -> t a
- forMaybe :: (Witherable t, Applicative f) => t a -> (a -> f (Maybe b)) -> f (t b)
- 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 :: 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
- hashNubOf :: (Eq a, Hashable a) => FilterLike' (State (HashSet a)) s a -> 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 Chipped t a = Chipped {
- getChipped :: t (Maybe a)
Documentation
class Traversable t => Witherable t where #
Like Traversable
, but you can remove elements instead of updating them.
A definition of wither
must satisfy the following laws:
- identity
wither
(pure
. Just) ≡pure
- composition
Compose
.fmap
(wither
f) .wither
g ≡wither
(Compose
.fmap
(wither
f) . g)
Parametricity implies the naturality law:
t .wither
f ≡wither
(t . f)
Methods
wither :: Applicative f => (a -> f (Maybe b)) -> t a -> f (t b) #
mapMaybe :: (a -> Maybe b) -> t a -> t b #
catMaybes :: t (Maybe a) -> t a #
filterA :: Applicative f => (a -> f Bool) -> t a -> f (t a) #
Instances
Witherable [] # | |
Witherable Maybe # | |
Witherable IntMap # | |
Witherable Seq # | |
Witherable Vector # | |
Monoid e => Witherable (Either e) # | |
Witherable (Proxy *) # | |
Witherable (Map k) # | |
Traversable t => Witherable (MaybeT t) # | |
(Eq k, Hashable k) => Witherable (HashMap k) # | |
Traversable t => Witherable (Chipped t) # | |
Witherable (Const * r) # | |
(Traversable f, Witherable g) => Witherable (Compose * * f g) # | |
witherM :: (Witherable t, Monad m) => (a -> MaybeT m b) -> t a -> m (t b) #
blightM :: (Monad m, Witherable t) => t a -> (a -> MaybeT m b) -> m (t b) #
ordNub :: (Witherable t, Ord a) => t a -> t a #
hashNub :: (Witherable t, Eq a, Hashable a) => t a -> t a #
forMaybe :: (Witherable t, Applicative f) => t a -> (a -> f (Maybe b)) -> f (t b) #
Generalization
type FilterLike f s t a b = (a -> f (Maybe b)) -> s -> f t #
This type allows combinators to take a Filter
specializing the parameter f
.
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 #
A simple FilterLike
.
type Filter' s a = forall f. Applicative f => FilterLike' f s a #
A simple Filter
.
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 #
forMaybeOf
==flip
mapMaybeOf :: FilterLike Identity s t a b -> (a -> Maybe b) -> s -> t #
mapMaybe
through a filter.
catMaybesOf :: FilterLike Identity s t (Maybe a) a -> s -> t #
catMaybes
through a filter.
filterOf :: FilterLike' Identity s a -> (a -> Bool) -> s -> s #
Filter each element of a structure targeted by a Filter
.
ordNubOf :: Ord a => FilterLike' (State (Set a)) s a -> s -> s #
Remove the duplicate elements through a filter.
hashNubOf :: (Eq a, Hashable a) => FilterLike' (State (HashSet a)) s a -> s -> s #
Remove the duplicate elements through a filter.
It is often faster than ordNubOf
, especially when the comparison is expensive.
Cloning
cloneFilter :: FilterLike (Peat a b) s t a b -> Filter s t a b #
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.
Constructors
Peat | |
Fields
|
Witherable from Traversable
Deprecated: Use 'Compose t Maybe' instead
Traversable containers which hold Maybe
are witherable.
Constructors
Chipped | Deprecated: Use 'Compose t Maybe' instead |
Fields
|
Instances
Functor t => Functor (Chipped t) # | |
Applicative t => Applicative (Chipped t) # | |
Foldable t => Foldable (Chipped t) # | |
Traversable t => Traversable (Chipped t) # | |
Traversable t => Witherable (Chipped t) # | |
Eq (t (Maybe a)) => Eq (Chipped t a) # | |
Ord (t (Maybe a)) => Ord (Chipped t a) # | |
Read (t (Maybe a)) => Read (Chipped t a) # | |
Show (t (Maybe a)) => Show (Chipped t a) # | |