An AVL Tree based set.
A set of unique values. The keys can be any type. This includes both custom and comparable types such as Int, Float, Time, Char, String, and tuples or lists of comparable types.
Insert, remove, get and member operations all take O(log n) time.
Size takes constant O(1) time.
A comparator is a function which compares two keys.
import AVL.Set as Set exposing (Comparator, Set)
type ID
= ID Int
compareID : Comparator ID
compareID (ID x) (ID y) =
compare x y
ids : Set ID User
ids =
Set.fromListWith compareID [ ID 0, ID 1, ID 2 ]
probs : List Bool
probs =
[ Set.member (ID 0)
, Set.member (ID 3)
]Create an empty set with comparable keys.
Create an empty set with custom keys.
Create a set with one comparable key.
Create a set with one custom key.
Convert an list into a set with comparable keys.
Convert an list into a set with custom keys.
Convert a set into a list, sorted from lowest to highest.
Insert a key into a set.
Remove a key from a set. If the key is not found, no changes are made.
Toggle a specific key.
Remove all entries from a set. Useful when you need to create new empty set using same comparator.
Determine if a set is empty.
Determine the number of elements in a set. It takes constant time to determine the size.
Determine if a value is in a set.
Map a function onto a set, creating a new set with no duplicates.
Only keep elements that pass the given test.
numbers : Set Int
numbers =
fromList [ -2, -1, 0, 1, 2 ]
positives : Set Int
positives =
filter (\x -> x > 0) numbers
-- positives == [ 0, 1, 2 ]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.
Fold 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.
Combine two sets.
Keep a key when them do not appear in the right set.
Keep a keys when them appear in the right set.
Represents a set of unique values. So (Set Int) is a set of integers and (Set ID) is a set of custom ID values.