# MutMap

`enum MutMap[k: Type, v: Type, r: Eff]`Source
`case MutMap(Region[r], Ref[Map[k, v], r])`

The Mutable Map type.

### Instances

`instance Iterable[MutMap[k, v, r]]`Source

## Definitions

`def adjust!(f: v -> v \ ef, k: k, m: MutMap[k, v, r]): Unit \ ef + r with Order[k]`

Updates the mutable map `m` with `k -> f(v)` if `k -> v` is in `m`.

Otherwise leaves the map is unchanged.

`def adjustWithKey!(f: k -> (v -> v \ ef), k: k, m: MutMap[k, v, r]): Unit \ ef + r with Order[k]`

Updates the mutable map `m` with `k -> f(k, v)` if `k -> v` is in `m`.

Otherwise leaves the map is unchanged.

`def clear!(m: MutMap[k, v, r]): Unit \ r`

Removes all mappings from the mutable map `m`.

`def copy(rc: Region[r1], m: MutMap[k, v, r]): MutMap[k, v, r1] \ r + r1`

Returns a shallow copy of the mutable map `m`.

`def count(f: k -> (v -> Bool \ ef), m: MutMap[k, v, r]): Int32 \ ef + r`

Returns the number of mappings in the mutable map `m` that satisfy the predicate function `f`.

Purity reflective: Runs in parallel when given a pure function `f`.

`def empty(rc: Region[r]): MutMap[k, v, r] \ r`

Returns a fresh empty mutable map.

`def exists(f: k -> (v -> Bool \ ef), m: MutMap[k, v, r]): Bool \ ef + r`

Returns `true` if and only if at least one mapping in the mutable map `m` satisfies the predicate function `f`.

Returns `false` if `m` is the empty map.

`def find(f: k -> (v -> Bool), m: MutMap[k, v, r]): Option[(k, v)] \ r`

Alias for `findLeft`.

The function `f` must be pure.

`def findLeft(f: k -> (v -> Bool), m: MutMap[k, v, r]): Option[(k, v)] \ r`

Optionally returns the first mapping of the mutable map `m` that satisfies the predicate function `f` when searching from left to right.

The function `f` must be pure.

`def findRight(f: k -> (v -> Bool), m: MutMap[k, v, r]): Option[(k, v)] \ r`

Optionally returns the first mapping of the mutable map `m` that satisfies the predicate function `f` when searching from right to left.

The function `f` must be pure.

`def foldLeft(f: b -> (v -> b \ ef), i: b, m: MutMap[k, v, r]): b \ ef + r`

Applies `f` to a start value `i` and all values in the mutable map `m` going from left to right.

That is, the result is of the form: `f(...f(f(i, v1), v2)..., vn)`.

`def foldLeftWithKey(f: b -> (k -> (v -> b \ ef)), i: b, m: MutMap[k, v, r]): b \ ef + r`

Applies `f` to a start value `i` and all key-value pairs in the mutable map `m` going from left to right.

That is, the result is of the form: `f(...f(k2, f(k1, i, v1), v2)..., vn)`.

`def foldRight(f: v -> (b -> b \ ef), s: b, m: MutMap[k, v, r]): b \ ef + r`

Applies `f` to a start value `s` and all values in the mutable map `m` going from right to left.

That is, the result is of the form: `f(v1, ...f(vn-1, f(vn, s)))`.

`def foldRightWithCont(f: v -> ((Unit -> b \ ef) -> b \ ef), z: b, m: MutMap[k, v, r]): b \ ef + r`

Applies `f` to a start value `z` and all values in the mutable map `m` going from right to left.

That is, the result is of the form: `f(v1, ...f(vn-1, f(vn, z)))`. A `foldRightWithCont` allows early termination by not calling the continuation.

`def foldRightWithKey(f: k -> (v -> (b -> b \ ef)), s: b, m: MutMap[k, v, r]): b \ ef + r`

Applies `f` to a start value `s` and all key-value pairs in the mutable map `m` going from right to left.

That is, the result is of the form: `f(k1, v1, ...f(kn-1, vn-1, f(kn, vn, s)))`.

`def foldRightWithKeyCont(f: k -> (v -> ((Unit -> b \ ef) -> b \ ef)), z: b, m: MutMap[k, v, r]): b \ ef + r`

Applies `f` to a start value `z` and all key-value pairs in the mutable map `m` going from right to left.

That is, the result is of the form: `f(k1, v1, ...f(kn-1, vn-1, f(kn, vn, z)))`. A `foldRightWithKeyCont` allows early termination by not calling the continuation.

`def foldWithKey(f: b -> (k -> (v -> b \ ef)), i: b, m: MutMap[k, v, r]): b \ ef + r`

Alias for `foldLeftWithKey`.

`def forAll(f: k -> (v -> Bool \ ef), m: MutMap[k, v, r]): Bool \ ef + r`

Returns `true` if and only if all mappings in the mutable map `m` satisfy the predicate function `f`.

Returns `true` if `m` is the empty map.

`def forEach(f: k -> (v -> Unit \ ef), m: MutMap[k, v, r]): Unit \ ef + r`

Applies `f` to all the `(key, value)` pairs in the mutable map `m`.

`def forEachWithIndex(f: Int32 -> (k -> (v -> Unit \ ef)), m: MutMap[k, v, r]): Unit \ ef + r`

Apply the effectful function `f` to all the `(key, value)` pairs in the mutable map `m` along with that element's index.

`def get(k: k, m: MutMap[k, v, r]): Option[v] \ r with Order[k]`

Returns `Some(v)` if `k -> v` is in the mutable map `m`.

Otherwise returns `None`.

`def getOrElsePut!(k: k, d: v, m: MutMap[k, v, r]): v \ r with Order[k]`

Returns `v` if `k -> v` is in the mutable map `m`.

Otherwise updates the mutable map `m` with a new mapping `k -> d` and returns d.

`def getWithDefault(k: k, d: v, m: MutMap[k, v, r]): v \ r with Order[k]`

Returns `v` if `k -> v` is in the mutable map `m`.

Otherwise returns `d`.

`def isEmpty(m: MutMap[k, v, r]): Bool \ r`

Returns `true` if and only if `m` is the empty map.

`def isProperSubmapOf(m1: MutMap[k, v, r1], m2: MutMap[k, v, r2]): Bool \ r1 + r2 with Order[k], Eq[v]`

Returns `true` if and only if all mappings in the mutable map `m1` occur in the mutable map `m2` and `m1 != m2`.

`def isSubmapOf(m1: MutMap[k, v, r1], m2: MutMap[k, v, r2]): Bool \ r1 + r2 with Order[k], Eq[v]`

Returns `true` if and only if all mappings in the mutable map `m1` occur in the mutable map `m2`.

`def iterator(rc: Region[r1], m: MutMap[k, v, r2]): Iterator[(k, v), r1 + r2, r1] \ r1 + r2`

Returns an iterator over all key-value pairs in `m`.

`def iteratorKeys(rc: Region[r1], m: MutMap[k, v, r2]): Iterator[k, r1 + r2, r1] \ r1 + r2`

Returns an iterator over keys in `m`.

`def iteratorValues(rc: Region[r1], m: MutMap[k, v, r2]): Iterator[v, r1 + r2, r1] \ r1 + r2`

Returns an iterator over values in `m`.

`def joinKeys(sep: String, m: MutMap[k, v, r]): String \ r with ToString[k]`

Returns the concatenation of the string representation of each key `k` in `m` with `sep` inserted between each element.

`def joinValues(sep: String, m: MutMap[k, v, r]): String \ r with ToString[v]`

Returns the concatenation of the string representation of each value `v` in `m` with `sep` inserted between each element.

`def joinWith(f: k -> (v -> String \ ef), sep: String, m: MutMap[k, v, r]): String \ ef + r`

Returns the concatenation of the string representation of each key-value pair `k => v` in `m` according to `f` with `sep` inserted between each element.

`def keysOf(m: MutMap[k, v, r]): Set[k] \ r with Order[k]`

Returns the keys of the mutable map `m`.

`def map(rc1: Region[r1], f: v1 -> v2 \ ef, m: MutMap[k, v1, r]): MutMap[k, v2, r1] \ ef + r + r1`

Returns a map with mappings `k => f(v)` for every `k => v` in `m`.

Purity reflective: Runs in parallel when given a pure function `f`.

`def mapWithKey(rc: Region[r1], f: k -> (v1 -> v2 \ ef), m: MutMap[k, v1, r]): MutMap[k, v2, r1] \ ef + r + r1`

Returns a map with mappings `k => f(k, v)` for every `k => v` in `m`.

Purity reflective: Runs in parallel when given a pure function `f`.

`def maximumKey(m: MutMap[k, v, r]): Option[(k, v)] \ r`

Optionally finds `k => v` where `k` is the largest key according to the `Order` instance of `k`.

Returns `None` if `m` is empty.

`def maximumKeyBy(cmp: k -> (k -> Comparison \ ef), m: MutMap[k, v, r]): Option[(k, v)] \ ef + r`

Optionally finds `k => v` where `k` is the largest key according to the given comparator `cmp`.

Returns `None` if `m` is empty.

Purity reflective: Runs in parallel when given a pure function `f`.

`@Parallel `
`def maximumValue(m: MutMap[k, v, r]): Option[(k, v)] \ r with Order[v]`

Optionally finds `k => v` where `v` is the largest value.

Returns `None` if `m` is empty.

`def maximumValueBy(cmp: v -> (v -> Comparison \ ef), m: MutMap[k, v, r]): Option[(k, v)] \ ef + r`

Optionally finds `k => v` where `v` is the largest value according to the given comparator `cmp`.

Returns `None` if `m` is empty.

Purity reflective: Runs in parallel when given a pure function `cmp`.

`def memberOf(k: k, m: MutMap[k, v, r]): Bool \ r with Order[k]`

Returns `true` if and only if the mutable map `m` contains the key `k`.

`def merge!(m1: MutMap[k, v, r1], m2: MutMap[k, v, r2]): Unit \ r1 + r2 with Order[k]`

Merges the mutable map `m1` into the mutable map `m2` in a left-biased manner.

That is, key collisions are resolved by taking the mapping from `m1`.

`def mergeWith!(f: v -> (v -> v \ ef), m1: MutMap[k, v, r1], m2: MutMap[k, v, r2]): Unit \ ef + r1 + r2 with Order[k]`

Merges the mutable map `m1` into the mutable map `m2` where key collisions are resolved with the merge function `f`.

`def mergeWithKey!(f: k -> (v -> (v -> v \ ef)), m1: MutMap[k, v, r1], m2: MutMap[k, v, r2]): Unit \ ef + r1 + r2 with Order[k]`

Merges the mutable map `m1` into the mutable map `m2` where key collisions are resolved with the merge function `f`, taking both the key and values.

`def minimumKey(m: MutMap[k, v, r]): Option[(k, v)] \ r`

Optionally finds `k -> v` where `k` is the smallest key according to the `Order` instance of `k`.

Returns `None` if `m` is empty.

`def minimumKeyBy(cmp: k -> (k -> Comparison \ ef), m: MutMap[k, v, r]): Option[(k, v)] \ ef + r`

Optionally finds `k => v` where `k` is the smallest key according to the given comparator `cmp`.

Returns `None` if `m` is empty.

Purity reflective: Runs in parallel when given a pure function `cmp`.

`@Parallel `
`def minimumValue(m: MutMap[k, v, r]): Option[(k, v)] \ r with Order[v]`

Optionally finds `k => v` where `v` is the smallest value.

Returns `None` if `m` is empty.

`def minimumValueBy(cmp: v -> (v -> Comparison \ ef), m: MutMap[k, v, r]): Option[(k, v)] \ ef + r`

Optionally finds `k => v` where `v` is the smallest value according to the given comparator `cmp`.

Returns `None` if `m` is empty.

Purity reflective: Runs in parallel when given a pure function `cmp`.

`def nonEmpty(m: MutMap[k, v, r]): Bool \ r`

Returns `true` if and only if `m` is a non-empty map.

`def put!(k: k, v: v, m: MutMap[k, v, r]): Unit \ r with Order[k]`

Updates the mutable map `m` with the binding `k -> v`. Replaces any existing binding.

`def putWith!(f: v -> (v -> v \ ef), k: k, v: v, m: MutMap[k, v, r]): Unit \ ef + r with Order[k]`

Updates the mutable map `m` with the binding `k -> f(v, v1)` if `k -> v1` is in `m`.

Otherwise updates the mutable map `m` with the binding `k -> v`.

`def rangeQuery(p: k -> Comparison \ ef, m: MutMap[k, v, r]): List[(k, v)] \ ef + r`

Extracts a range of key-value pairs from the mutable map `m`.

That is, the result is a list of all pairs `(k, v)` where `p(k)` returns `Equal`.

`def rangeQueryWith(p: k -> Comparison \ ef1, f: k -> (v -> Unit \ ef2), m: MutMap[k, v, r]): Unit \ ef1 + ef2 + r`

Applies `f` to all key-value pairs `(k, v)` in the mutable map `m` where `p(k)` returns `EqualTo`.

`def reduceLeft(f: v -> (v -> v \ ef), m: MutMap[k, v, r]): Option[v] \ ef + r`

Applies `f` to all values in the mutable map `m` going from left to right until a single value `v` is obtained. Returns `Some(v)`.

That is, the result is of the form: `Some(f(...f(f(v1, v2), v3)..., vn))`

Returns `None` if `m` is the empty map.

`def reduceLeftWithKey(f: k -> (v -> (k -> (v -> (k, v) \ ef))), m: MutMap[k, v, r]): Option[(k, v)] \ ef + r`

Applies `f` to all mappings in the mutable map `m` going from left to right until a single mapping `(k, v)` is obtained. Returns `Some((k, v))`.

That is, the result is of the form: `Some(f(...f(f(k1, v1, k2, v2), k3, v3)..., kn, vn))`

Returns `None` if `m` is the empty map.

`def reduceRight(f: v -> (v -> v \ ef), m: MutMap[k, v, r]): Option[v] \ ef + r`

Applies `f` to all values in the mutable map `m` going from right to left until a single value `v` is obtained. Returns `Some(v)`.

That is, the result is of the form: `Some(f(v1, ...f(vn-2, f(vn-1, vn))...))`

Returns `None` if `m` is the empty map.

`def reduceRightWithKey(f: k -> (v -> (k -> (v -> (k, v) \ ef))), m: MutMap[k, v, r]): Option[(k, v)] \ ef + r`

Applies `f` to all mappings in the mutable map `m` going from right to left until a single mapping `(k, v)` is obtained. Returns `Some((k, v))`.

That is, the result is of the form: `Some(f(k1, v1, ...f(kn-2, vn-2, f(kn-1, vn-1, kn, vn))...))`

Returns `None` if `m` is the empty map.

`def refine!(f: v -> Bool, m: MutMap[k, v, r]): Unit \ r with Order[k]`

Removes all mappings `k -> v` from the mutable map `m` where `v` does not satisfy the predicate function `f`.

The function `f` must be pure.

`def refineWithKey!(f: k -> (v -> Bool), m: MutMap[k, v, r]): Unit \ r with Order[k]`

Removes all mappings `k -> v` from the mutable map `m` where `(k, v)` does not satisfy the predicate function `f`.

The function `f` must be pure.

`def remove!(k: k, m: MutMap[k, v, r]): Unit \ r with Order[k]`

Removes the mapping `k` from the mutable map `m`.

Leaves the map unchanged if the mutable map `m` does not contain any mapping for `k`.

`def sameElements(a: MutMap[k, v, r1], b: MutMap[k, v, r2]): Bool \ r1 + r2 with Order[k], Eq[v]`

Returns `true` if MutMaps `a` and `b` have the same elements, i.e. are structurally equal.

`def singleton(rc: Region[r], k: k, v: v): MutMap[k, v, r] \ r with Order[k]`

Returns the singleton map where key `k` is mapped to value `v`.

`def size(m: MutMap[k, v, r]): Int32 \ r`

Returns the size of the mutable map `m`.

`def sumKeys(m: MutMap[Int32, v, r]): Int32 \ r`

Returns the sum of all keys in the map `m`.

`def sumValues(m: MutMap[k, Int32, r]): Int32 \ r`

Returns the sum of all values in the map `m`.

`def sumWith(f: k -> (v -> Int32 \ ef), m: MutMap[k, v, r]): Int32 \ ef + r`

Returns the sum of all key-value pairs `k => v` in the map `m` according to the function `f`.

Purity reflective: Runs in parallel when given a pure function `f`.

`def toArray(rc1: Region[r1], m: MutMap[k, v, r]): Array[(k, v), r1] \ r + r1`

Returns the mutable map `m` as an array of key-value pairs.

`def toList(m: MutMap[k, v, r]): List[(k, v)] \ r`

Returns the mutable map `m` as a list of key-value pairs.

`def toMap(m: MutMap[k, v, r]): Map[k, v] \ r`

Returns the mutable map `m` as an immutable map.

`def toMutDeque(rc1: Region[r1], m: MutMap[k, v, r2]): MutDeque[(k, v), r1] \ r2 + r1`

Returns `m` as a MutDeque.

`def toSet(m: MutMap[k, v, r]): Set[(k, v)] \ r with Order[k], Order[v]`

Returns the mutable map `m` as a set of key-value pairs.

`def toString(m: MutMap[k, v, r]): String \ r with ToString[k], ToString[v]`

Returns a string representation of the given MutMap `m`.

`def toVector(m: MutMap[k, v, r]): Vector[(k, v)] \ r`

Returns the mutable map `m` as a vector of key-value pairs.

`def transform!(f: v -> v \ ef, m: MutMap[k, v, r]): Unit \ ef + r with Order[k]`

Applies the function `f` to every value in the mutable map `m`.

`def transformWithKey!(f: k -> (v -> v \ ef), m: MutMap[k, v, r]): Unit \ ef + r with Order[k]`

Applies the function `f` to every value in the mutable map `m`.

`def valuesOf(m: MutMap[k, v, r]): List[v] \ r`

Returns the values of the mutable map `m`.