Dictionary
Import Dictionary for an insertion-ordered association structure whose keys
require equality but not ordering. The representation and constructor are
private; every update returns a new dictionary. Basic shape operations are
O(1); key lookup and update are O(n) worst case.
Type
Dictionary
Dictionary(k, v) associates keys of type k with values of type v and
preserves the insertion position of each key.
Construction
dictionaryEmpty
dictionarySingleton
dictionaryFromList
Inserts pairs from left to right. A duplicate key keeps its first position and
its last value. Construction is O(n²) worst case.
dictionaryToList
Returns key-value pairs in insertion order. This is O(1) at the API boundary.
Size and lookup
dictionarySize
dictionaryIsEmpty
dictionaryLookup
Returns the associated value as Just, or Nothing when the key is absent.
Lookup is O(n) worst case.
dictionaryGetOr
Returns the associated value, or the final fallback argument when the key is
absent. Lookup is O(n) worst case.
dictionaryContainsKey
Updating
dictionaryInsert
Adds a new key at the end or replaces an existing value without moving its key.
dictionaryReplace
Replaces an existing value without moving its key. Returns Nothing when the
key is absent. The update is O(n).
dictionaryRemove
Removes the key and its value. An absent key returns an equivalent dictionary.
Remaining keys retain their order. The update is O(n).
dictionaryUpdate
Calls the function with the current value as Just, or Nothing when absent.
Returning Nothing removes an existing key; returning Just replaces it or
appends a new key. The update is O(n) plus callback work.
Views and traversal
dictionaryKeys
Returns keys in insertion order in O(n).
dictionaryValues
Returns values in their keys' insertion order in O(n).
dictionaryMapValues
Transforms every value in insertion order while preserving keys and their
positions. This is O(n) plus callback work.
dictionaryFilter
Keeps pairs whose predicate returns True, preserving their relative insertion
order. This is O(n) plus callback work.
dictionaryFoldLeft
Folds pairs from earliest to latest insertion, starting with the supplied
accumulator. This is O(n) plus callback work.
dictionaryFoldRight
Folds pairs from latest to earliest insertion, starting with the supplied
terminal value. This is O(n) plus callback work.
Use Map when ascending key order and logarithmic lookup matter more
than insertion order and Eq-only keys.