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:

  • filterDefault

Members

Instances

#eitherBool Source

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

Upgrade a boolean-style predicate to an either-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.

#maybeBool Source

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

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

#filterDefault Source

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

A default implementation of filter using filterMap.

#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.