witherable-0.1.2: Generalization of filter and catMaybes

Copyright(c) Fumiaki Kinoshita 2015
LicenseBSD3
MaintainerFumiaki Kinoshita <fumiexcel@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Witherable

Description

This module generalizes filterable containers.

Synopsis

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

filter :: (a -> Bool) -> t a -> t a Source

witherM :: (Witherable t, Monad m) => (a -> MaybeT m b) -> t a -> m (t b) Source

blightM :: (Monad m, Witherable t) => t a -> (a -> MaybeT m b) -> m (t b) Source

blightM is witherM with its arguments flipped.