O(log n). Insert with a function, combining new value and old value.
insertWith f key value mp
will insert the pair (key, value) into mp if key does
not exist in the map. If the key does exist, the function will
insert the pair (key, f new_value old_value).

O(log n). Insert with a function, combining key, new value and old value.
insertWithKey f key value mp
will insert the pair (key, value) into mp if key does
not exist in the map. If the key does exist, the function will
insert the pair (key,f key new_value old_value).
Note that the key passed to f is the same key passed to insertWithKey.

O(log n). Combines insert operation with old value retrieval.
The expression (insertLookupWithKey f k x map)
is a pair where the first element is equal to (lookup k map)
and the second element equal to (insertWithKey f k x map).

O(log n). The expression (updateWithKey f k map) updates the
value x at k (if it is in the map). If (f k x) is Nothing,
the element is deleted. If it is (Just y), the key k is bound
to the new value y.

interactiveAlter :: Int -> Map Int String -> IO (Map Int String)
interactiveAlter k m = alterF f k m where
f Nothing -> do
putStrLn $ show k ++
" was not found in the map. Would you like to add it?"
getUserResponse1 :: IO (Maybe String)
f (Just old) -> do
putStrLn "The key is currently bound to " ++ show old ++
". Would you like to change or delete it?"
getUserresponse2 :: IO (Maybe String)

alterF is the most general operation for working with an individual
key that may or may not be in a given map. When used with trivial
functors like Identity and Const, it is often slightly slower than
more specialized combinators like lookup and insert. However, when
the functor is non-trivial and key comparison is not particularly cheap,
it is the fastest way.

Note on rewrite rules:

This module includes GHC rewrite rules to optimize alterF for
the Const and Identity functors. In general, these rules
improve performance. The sole exception is that when using
Identity, deleting a key that is already absent takes longer
than it would without the rules. If you expect this to occur
a very large fraction of the time, you might consider using a
private copy of the Identity type.

O(n+m). Difference with a combining function.
When two equal keys are
encountered, the combining function is applied to the values of these keys.
If it returns Nothing, the element is discarded (proper set difference). If
it returns (Just y), the element is updated with a new value y.

O(n+m). Difference with a combining function. When two equal keys are
encountered, the combining function is applied to the key and both values.
If it returns Nothing, the element is discarded (proper set difference). If
it returns (Just y), the element is updated with a new value y.

WhenMissing tactics

Traverse over the entries whose keys are missing from the other map,
optionally producing values to put in the result.
This is the most powerful WhenMissing tactic, but others are usually
more efficient.

When calling mergeWithKey combine only1 only2, a function combining two
Maps is created, such that

if a key is present in both maps, it is passed with both corresponding
values to the combine function. Depending on the result, the key is either
present in the result with specified value, or is left out;

a nonempty subtree present only in the first map is passed to only1 and
the output is added to the result;

a nonempty subtree present only in the second map is passed to only2 and
the output is added to the result.

The only1 and only2 methods must return a map with a subset (possibly empty) of the keys of the given map.
The values can be modified arbitrarily. Most common variants of only1 and
only2 are id and constempty, but for example map f,
filterWithKey f, or mapMaybeWithKey f could be used for any f.

O(n*log n).
mapKeysWith c f s is the map obtained by applying f to each key of s.

The size of the result may be smaller if f maps two or more distinct
keys to the same new key. In this case the associated values will be
combined using c. The value at the greater of the two original keys
is used as the first argument to c.

O(n).
mapKeysMonotonic f s == mapKeys f s, but works only when f
is strictly monotonic.
That is, for any values x and y, if x < y then f x < f y.
The precondition is not checked.
Semi-formally, we have:

Note: if p is not actually antitone, then spanAntitone will split the map
at some unspecified point where the predicate switches from holding to not
holding (where the predicate is seen to hold before the first key and to fail
after the last key).

O(1). Decompose a map into pieces based on the structure of the underlying
tree. This function is useful for consuming a map in parallel.

No guarantee is made as to the sizes of the pieces; an internal, but
deterministic process determines this. However, it is guaranteed that the pieces
returned will be in ascending order (all elements in the first submap less than all
elements in the second, and so on).

O(m*log(n/m + 1)), m <= n.
The expression (isSubmapOfBy f t1 t2) returns True if
all keys in t1 are in tree t2, and when f returns True when
applied to their respective values. For example, the following
expressions are all True:

O(m*log(n/m + 1)), m <= n. Is this a proper submap? (ie. a submap but not equal).
The expression (isProperSubmapOfBy f m1 m2) returns True when
m1 and m2 are not equal,
all keys in m1 are in m2, and when f returns True when
applied to their respective values. For example, the following
expressions are all True:

O(log n). Return the index of a key, which is its zero-based index in
the sequence sorted by keys. The index is a number from 0 up to, but not
including, the size of the map. Calls error when the key is not
a member of the map.

O(log n). Retrieve an element by its index, i.e. by its zero-based
index in the sequence sorted by keys. If the index is out of range (less
than zero, greater or equal to size of the map), error is called.