opvasger / comparable / Comparable.Set

A set of unique values. The values can be any type.

Sets


type Set value

Represents a set of unique values.

Compare

equals : Set value -> Set value -> Basics.Bool

Determine if two sets contain the same values.

Build

empty : Set value

Create an empty set.

singleton : value -> Set value

Create a set with one value.

insert : Comparable value -> value -> Set value -> Set value

Insert a value into a set.

remove : Comparable value -> value -> Set value -> Set value

Remove a value from a set. If the value is not found, no changes are made.

Query

isEmpty : Set value -> Basics.Bool

Determine if a set is empty.

member : Comparable value -> value -> Set value -> Basics.Bool

Determine if a value is in a set.

size : Set value -> Basics.Int

Determine the number of elements in a set.

Combine

union : Comparable value -> Set value -> Set value -> Set value

Get the union of two sets. Keep all values.

intersect : Comparable value -> Set value -> Set value -> Set value

Get the intersection of two sets. Keeps values that appear in both sets.

diff : Comparable value -> Set value -> Set value -> Set value

Get the difference between the first set and the second. Keeps values that do not appear in the second set.

List

toList : Set value -> List value

Convert a set into a list, sorted from lowest to highest.

fromList : Comparable value -> List value -> Set value

Convert a list into a set, removing any duplicates.

Transform

map : Comparable otherValue -> (value -> otherValue) -> Set value -> Set otherValue

Map a function onto a set, creating a new set with no duplicates.

foldl : (value -> accumulator -> accumulator) -> accumulator -> Set value -> accumulator

Fold over the values in a set, in compare from lowest to highest.

foldr : (value -> accumulator -> accumulator) -> accumulator -> Set value -> accumulator

Fold over the values in a set, in compare from highest to lowest.

filter : Comparable value -> (value -> Basics.Bool) -> Set value -> Set value

Only keep elements that pass the given test.

partition : Comparable value -> (value -> Basics.Bool) -> Set value -> ( Set value, Set value )

Create two new sets. The first contains all the elements that passed the given test, and the second contains all the elements that did not.