A set of unique values.
Insert, remove, and query operations all take O(log n) time.
This implementation is based on
Skinney/elm-dict-exploration,
except that it uses Sorter instead of comparable, so it permits keys
that are not comparable.
Create an empty set.
Create a set with one value.
Insert a value into a set.
Remove a value from a set. If the value is not found, no changes are made.
Determine if a set is empty.
Return True if the given value is in the given set.
Return the number of elements in a set.
Get the union of two sets. Keep all values.
Convert a set into a list, sorted from lowest to highest.
Convert a list into a set, removing any duplicates.
Map a function onto a set, creating a new set with no duplicates.
Only keep elements that pass the given test.
numbers =
Set.fromList [ -2, -1, 0, 1, 2, 3, 4, 5 ]
positives =
Set.keepIf (\num -> num > 0) numbers
evens =
Set.keepIf (\num -> num % 2 == 0) numbers
positiveEvens =
-- Intersection
Set.keepIf (Set.member evens) positivesRemove elements that pass the given test.
numbers =
Set.fromList [ -2, -1, 0, 1, 2, 3, 4, 5 ]
positives =
Set.dropIf (\num -> num <= 0) numbers
evens =
Set.dropIf (\num -> num % 2 == 1) numbers
positiveOdds =
-- Difference
Set.dropIf (Set.member evens) positivesFold over the values in a set, in order from lowest to highest.
Fold over the values in a set, in order from highest to lowest.
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.
Represents a set of unique values. So
(Set Int)is a set of integers and(Set String)is a set of strings.