Map
Import Map for a persistent balanced search tree. Keys require Ord(k), and
ordered views traverse keys in ascending order. The representation and
constructor are private. Lookup and update are O(log n); full views and folds
are O(n) before callback work.
Type
Map
Map(k, v) associates ordered keys of type k with values of type v.
Construction
mapEmpty
mapSingleton
mapFromList
Inserts pairs from left to right. The last value for a duplicate key wins.
Construction is O(n log n).
mapToList
Returns pairs in ascending key order in O(n).
Size and lookup
mapSize
mapIsEmpty
mapLookup
Returns the associated value as Just, or Nothing when absent. Lookup is
O(log n).
mapGetOr
Returns the associated value, or the final fallback argument when absent.
Lookup is O(log n).
mapContainsKey
Updating
mapInsert
Adds a key or replaces its value.
mapReplace
Replaces an existing value and returns the new map as Just. An absent key
returns Nothing. This is O(log n).
mapRemove
Removes a key when present. An absent key returns an equivalent map. This is
O(log n).
mapUpdate
Calls the function with the current value as Just, or Nothing when absent.
Returning Nothing removes a key; returning Just inserts or replaces it. This
is O(log n) plus callback work.
Ordered boundaries
mapMinimum
Returns the least key and its value, or Nothing for an empty map. This is
O(log n).
mapMaximum
Returns the greatest key and its value, or Nothing for an empty map. This is
O(log n).
mapPopMinimum
Returns the least pair and a map without it, or Nothing when empty. This is
O(log n).
mapPopMaximum
Returns the greatest pair and a map without it, or Nothing when empty. This
is O(log n).
Views and traversal
mapKeys
Returns keys in ascending order in O(n).
mapValues
Returns values in ascending key order in O(n).
mapMapValues
Transforms values in ascending key order while preserving keys and tree shape.
This is O(n) plus callback work.
mapFilter
Keeps pairs whose predicate returns True. Callbacks run in ascending key
order. Rebuilding the result is O(n log n) worst case.
mapFoldLeft
Folds pairs from least to greatest key in O(n) plus callback work.
mapFoldRight
Folds pairs from greatest to least key in O(n) plus callback work.
Use Dictionary when insertion order and Eq-only keys matter
more than sorted traversal and logarithmic lookup.