| 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
- 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.
traversef ≡wither(fmapJust. f)
A definition of wither must satisfy the following laws:
- identity
wither(pure. Just) ≡pure- composition
Compose . fmap (witherf) .witherg ≡wither(Compose . fmap (witherf) . g)
Parametricity implies the naturality law:
t .witherf =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
mapMaybe :: (a -> Maybe b) -> t a -> 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