| Copyright | (c) Fumiaki Kinoshita 2015 |
|---|---|
| License | BSD3 |
| Maintainer | Fumiaki Kinoshita <fumiexcel@gmail.com> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Witherable
Description
This module generalizes filterable containers.
- class Traversable t => Witherable t where
- wither :: Applicative f => (a -> f (Maybe b)) -> t a -> f (t b)
- catMaybes :: t (Maybe a) -> t a
- filterA :: Applicative f => (a -> f Bool) -> t a -> f (t a)
- filter :: (a -> Bool) -> t a -> t a
- 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)
Documentation
class Traversable t => Witherable t where Source
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:
- identity
wither (pure . Just) ≡ pure- composition
Compose . fmap (wither f) . wither g ≡ wither (Compose . fmap (maybe (pure Nothing) f) . g)
Parametricity implies the naturality law:
t . wither f = wither (t . f)
Minimal complete definition: wither or catMaybes.
The default definitions can be overriden for efficiency.
Minimal complete definition
Nothing
Methods
wither :: Applicative f => (a -> f (Maybe b)) -> t a -> f (t b) Source
catMaybes :: t (Maybe a) -> t a Source
filterA :: Applicative f => (a -> f Bool) -> t a -> f (t a) Source
Instances
| Witherable [] | |
| Witherable Maybe | |
| Witherable IntMap | |
| Witherable Seq | |
| Witherable Vector | |
| Monoid e => Witherable (Either e) | |
| Witherable (Const r) | |
| Witherable (Proxy *) | |
| Ord k => Witherable (Map k) | |
| (Eq k, Hashable k) => Witherable (HashMap k) |
witherM :: (Witherable t, Monad m) => (a -> MaybeT m b) -> t a -> m (t b) Source