Data.Witherable
- Package
- purescript-filterable
- Repository
- LiamGoodacre/purescript-filterable
#Witherable Source
class (Filterable t, Traversable t) <= Witherable t whereWitherable represents data structures which can be partitioned with
effects in some Applicative functor.
wilt- partition a structure with effectswither- filter a structure with effects
Laws:
- Naturality:
t <<< wither f ≡ wither (t <<< f) - Identity:
wither (pure <<< Just) ≡ pure - Composition:
Compose <<< map (wither f) <<< wither g ≡ wither (Compose <<< map (wither f) <<< g) - Multipass partition:
wilt p ≡ map separate <<< traverse p - Multipass filter:
wither p ≡ map compact <<< traverse p
Superclass equivalences:
partitionMap p = runIdentity <<< wilt (Identity <<< p)filterMap p = runIdentity <<< wither (Identity <<< p)traverse f ≡ wither (map Just <<< f)
Default implementations are provided by the following functions:
wiltDefaultwitherDefaultpartitionMapByWiltfilterMapByWithertraverseByWither
Members
wilt :: forall r l a m. Applicative m => (a -> m (Either l r)) -> t a -> m { left :: t l, right :: t r }wither :: forall b a m. Applicative m => (a -> m (Maybe b)) -> t a -> m (t b)
Instances
Witherable ArrayWitherable List(Ord k) => Witherable (Map k)Witherable Maybe(Monoid m) => Witherable (Either m)
#partitionMapByWilt Source
partitionMapByWilt :: forall r l a t. Witherable t => (a -> Either l r) -> t a -> { left :: t l, right :: t r }A default implementation of partitionMap given a Witherable.
#filterMapByWither Source
filterMapByWither :: forall b a t. Witherable t => (a -> Maybe b) -> t a -> t bA default implementation of filterMap given a Witherable.
#traverseByWither Source
traverseByWither :: forall b a m t. Witherable t => Applicative m => (a -> m b) -> t a -> m (t b)A default implementation of traverse given a Witherable.
#wilted Source
wilted :: forall r l m t. Witherable t => Applicative m => t (m (Either l r)) -> m { left :: t l, right :: t r }Partition between Left and Right values - with effects in m.
#withered Source
withered :: forall x m t. Witherable t => Applicative m => t (m (Maybe x)) -> m (t x)Filter out all the Nothing values - with effects in m.
#witherDefault Source
witherDefault :: forall b a m t. Witherable t => Applicative m => (a -> m (Maybe b)) -> t a -> m (t b)A default implementation of wither using compact.
#wiltDefault Source
wiltDefault :: forall r l a m t. Witherable t => Applicative m => (a -> m (Either l r)) -> t a -> m { left :: t l, right :: t r }A default implementation of wilt using separate
Re-exports from Data.Filterable
#Filterable Source
class (Compactable f, Functor f) <= Filterable f Filterable represents data structures which can be partitioned/filtered.
partitionMap- partition a data structure based on an either predicate.partition- partition a data structure based on boolean predicate.filterMap- map over a data structure and filter based on a maybe.filter- filter a data structure based on a boolean.
Laws:
Functor Relation:
filterMap identity ≡ compactFunctor Identity:
filterMap Just ≡ identityKleisli Composition:
filterMap (l <=< r) ≡ filterMap l <<< filterMap rfilter ≡ filterMap <<< maybeBoolfilterMap p ≡ filter (isJust <<< p)Functor Relation:
partitionMap identity ≡ separateFunctor Identity 1:
_.right <<< partitionMap Right ≡ identityFunctor Identity 2:
_.left <<< partitionMap Left ≡ identityf <<< partition ≡ partitionMap <<< eitherBoolwheref = \{ no, yes } -> { left: no, right: yes }f <<< partitionMap p ≡ partition (isRight <<< p)wheref = \{ left, right } -> { no: left, yes: right}
Default implementations are provided by the following functions:
partitionDefaultpartitionDefaultFilterpartitionDefaultFilterMappartitionMapDefaultfilterDefaultfilterDefaultPartitionfilterDefaultPartitionMapfilterMapDefault
Instances
Filterable ArrayFilterable Maybe(Monoid m) => Filterable (Either m)Filterable List(Ord k) => Filterable (Map k)