red-g / filter / Filter

Useful ways to combine filters (also known as predicates)!


type Filter a

A Filter takes a value a and determines whether it should pass or fail.


type Status
    = Pass
    | Fail

The result of a filter.

all : List (Filter a) -> Filter a

Pass if all filters pass.

and : Filter a -> Filter a -> Filter a

Pass if both filters pass.

any : List (Filter a) -> Filter a

Pass if at least one filter passes.

array : Filter a -> Array a -> Array a

Keep items that pass the filter.

by : (a -> b) -> Filter b -> Filter a

Filter a value by a derived property, like its height.

bob =
    { height = 5 }

isTall =
    by .height <| gt 6

test isTall bob
-- Fail

custom : (a -> Status) -> Filter a

Sometimes the building blocks in this library aren't enough!

eq : a -> Filter a

Test whether a value is equal to ref.

fail : Filter a

A filter that always fails.

gt : Basics.Int -> Filter Basics.Int

Test whether a value is greater than num.

list : Filter a -> List a -> List a

Keep items that pass the filter.

lt : Basics.Int -> Filter Basics.Int

Test whether a value is less than num.

not : Filter a -> Filter a

Flip the outcome of a filter; if it fails it passes, and if it passes it fails.

or : Filter a -> Filter a -> Filter a

Pass if at least one filter passes.

pass : Filter a

A filter that always passes.

test : Filter a -> a -> Status

Run an item through a given filter.

gte : Basics.Int -> Filter Basics.Int

Test whether a value is greater than or equal to num.

lte : Basics.Int -> Filter Basics.Int

Test whether a value is less than or equal to num.

neq : a -> Filter a

Test whether a value is not equal to ref.