Module

Data.Filterable

Package
purescript-filterable
Repository
LiamGoodacre/purescript-filterable

#Filterable Source

class (Functor f) <= Filterable f  where

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:

  • map f ≡ filterMap (Just <<< f)
  • filter ≡ filterMap <<< maybeBool
  • filterMap p ≡ filter (isJust <<< p)

Default implementations are provided by the following functions:

  • partitionDefault
  • partitionDefaultFilter
  • partitionDefaultFilterMap
  • filterDefault
  • filterDefaultPartition
  • filterDefaultPartitionMap

Members

Instances

#eitherBool Source

eitherBool :: forall a. (a -> Boolean) -> a -> Either a a

Upgrade a boolean-style predicate to an either-style predicate mapping.

#maybeBool Source

maybeBool :: forall a. (a -> Boolean) -> a -> Maybe a

Upgrade a boolean-style predicate to a maybe-style predicate mapping.

#partitionDefault Source

partitionDefault :: forall a f. Filterable f => (a -> Boolean) -> f a -> { no :: f a, yes :: f a }

A default implementation of partition using partitionMap.

#partitionDefaultFilter Source

partitionDefaultFilter :: forall a f. Filterable f => (a -> Boolean) -> f a -> { no :: f a, yes :: f a }

A default implementation of partition using filter. Note that this is almost certainly going to be suboptimal compared to direct implementations.

#partitionDefaultFilterMap Source

partitionDefaultFilterMap :: forall a f. Filterable f => (a -> Boolean) -> f a -> { no :: f a, yes :: f a }

A default implementation of partition using filterMap. Note that this is almost certainly going to be suboptimal compared to direct implementations.

#filterDefault Source

filterDefault :: forall a f. Filterable f => (a -> Boolean) -> f a -> f a

A default implementation of filter using filterMap.

#filterDefaultPartition Source

filterDefaultPartition :: forall a f. Filterable f => (a -> Boolean) -> f a -> f a

A default implementation of filter using partition.

#filterDefaultPartitionMap Source

filterDefaultPartitionMap :: forall a f. Filterable f => (a -> Boolean) -> f a -> f a

A default implementation of filter using partitionMap.

#partitioned Source

partitioned :: forall r l f. Filterable f => f (Either l r) -> { left :: f l, right :: f r }

#filtered Source

filtered :: forall a f. Filterable f => f (Maybe a) -> f a

Filter out all the Nothing values.

#cleared Source

cleared :: forall b a f. Filterable f => f a -> f b

Filter out all values.