A dictionary implementation using List
. The keys can be any type includes
recodes and custom type. This module provides all functions does Dict
, except
'foldl', 'foldr', 'merge'.
Insert, remove, and query operations all take O(n) time. Only for a few elements.
To determine equality, use 'eq' instead of '(==)'.
A dictionary of keys and values.
empty : Dict k v
Create an empty dictionary.
singleton : k -> v -> Dict k v
Create a dictionary with one key-value pair.
insert : k -> v -> Dict k v -> Dict k v
Insert a key-value pair into a dictionary. Replaces value when there is a collision.
update : k -> (Maybe v -> Maybe v) -> Dict k v -> Dict k v
Update the value of a dictionary for a specific key with a given function.
remove : k -> Dict k v -> Dict k v
Remove a key-value pair from a dictionary. If the key is not found, no changes are made.
isEmpty : Dict k v -> Basics.Bool
Determine if a dictionary is empty.
member : k -> Dict k v -> Basics.Bool
Determine if a key is in a dictionary.
get : k -> Dict k v -> Maybe v
Get the value associated with a key.
size : Dict k v -> Basics.Int
Determine the number of key-value pairs in the dictionary.
eq : Dict k v -> Dict k v -> Basics.Bool
Determine if given two dictionary are the same.
keys : Dict k v -> List k
Get all of the keys in a dictionary. The order is not Fixed.
values : Dict k v -> List v
Get all of the values in a dictionary. The order is not Fixed.
toList : Dict k v -> List ( k, v )
Convert a dictionary into an association list of key-value pairs. The order is not Fixed.
fromList : List ( k, v ) -> Dict k v
Convert an association list into a dictionary. This function takes O(n^2) for n-element list.
map : (k -> a -> b) -> Dict k a -> Dict k b
Apply a function to all values in a dictionary.
fold : (k -> v -> b -> b) -> b -> Dict k v -> b
Fold over the key-value pairs in a dictionary. The order is not fixed.
filter : (k -> v -> Basics.Bool) -> Dict k v -> Dict k v
Keep only the key-value pairs that pass the given test.
partition : (k -> v -> Basics.Bool) -> Dict k v -> ( Dict k v, Dict k v )
Partition a dictionary according to some test. The first dictionary contains all key-value pairs which passed the test, and the second contains the pairs that did not.
union : Dict k v -> Dict k v -> Dict k v
Combine two dictionaries. If there is a collision, preference is given to the first dictionary.
intersect : Dict k v -> Dict k v -> Dict k v
Keep a key-value pair when its key appears in the second dictionary. Preference is given to values in the first dictionary.
diff : Dict k a -> Dict k b -> Dict k a
Keep a key-value pair when its key does not appear in the second dictionary.