witherable-0.1.2.2: Generalization of filter and catMaybes

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

Data.Witherable

Description

 

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 (wither f) . g)

Parametricity implies the naturality law:

t . wither f = wither (t . f)

Minimal complete definition: wither or mapMaybe or catMaybes. The default definitions can be overridden 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

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.

newtype Chipped t a Source

Traversable containers which hold Maybe are witherable.

Constructors

Chipped 

Fields

getChipped :: t (Maybe a)
 

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)