Map
Definitions
def adjust(f: v -> v \ ef, k: k, m: Map[k, v]): Map[k, v] \ ef
SourceUpdates m
with k => f(v)
if k => v
is in m
.
Otherwise, returns m
.
def adjustWithKey(f: k -> (v -> v \ ef), k: k, m: Map[k, v]): Map[k, v] \ ef
SourceUpdates m
with k => f(k, v)
if k => v
is in m
. Otherwise, returns m
.
@ParallelWhenPure
def count(f: k -> (v -> Bool \ ef), m: Map[k, v]): Int32 \ ef
SourceReturns the number of mappings k => v
in m
that satisfy the predicate f
.
Purity reflective: Runs in parallel when given a pure function f
.
def difference(m1: Map[k, v], m2: Map[k, v]): Map[k, v]
SourceReturns the difference of m1
and m2
, i.e. m1 - m2
.
That is, returns the map m1
with the keys removed that are in m2
.
def differenceWith(f: v -> (v -> Option[v] \ ef), m1: Map[k, v], m2: Map[k, v]): Map[k, v] \ ef
SourceReturns the difference of m1
and m2
, i.e. m1 - m2
.
When a key k
is in both m1
and m2
, the associated values are passed to the merge function f
.
If f
returns None
the mapping with k
is thrown away (proper set difference).
If f
returns Some(v)
the mapping k => v
is included in the result.
def differenceWithKey(f: k -> (v -> (v -> Option[v] \ ef)), m1: Map[k, v], m2: Map[k, v]): Map[k, v] \ ef
SourceReturns the difference of m1
and m2
, i.e. m1 - m2
.
When a key k
is in both m1
and m2
, k
and the associated values are passed to the merge function f
.
If f
returns None
the mapping with k
is thrown away (proper set difference).
If f
returns Some(v)
the mapping k => v
is included in the result.
def empty(_unit: Unit): Map[k, v]
SourceReturns the empty map.
Map#{}
is syntactic sugar for empty
(Map#{} = empty()
).
@ParallelWhenPure
def exists(f: k -> (v -> Bool \ ef), m: Map[k, v]): Bool \ ef
SourceReturns true
if and only if at least one mapping in m
satisfies the predicate f
.
Returns false
if m
is the empty map.
Purity reflective: Runs in parallel when given a pure function f
.
def explode(m: Map[k, t[v]]): Set[(k, v)]
SourceReturns the set of tuples (k, v)
where v
is a value in t
and k => t
.
def filter(f: v -> Bool \ ef, m: Map[k, v]): Map[k, v] \ ef
SourceReturns a map of all mappings k => v
in m
where v
satisfies the predicate f
.
def filterMap(f: a -> Option[b] \ ef, m: Map[k, a]): Map[k, b] \ ef
SourceReturns a map of all mappings k => v1
in m
where applying the function f
to v
produces
a Some(v1)
. Elements that produce None
are discarded.
def filterMapWithKey(f: k -> (a -> Option[b] \ ef), m: Map[k, a]): Map[k, b] \ ef
SourceReturns a map of all mappings k => v1
in m
where applying the function f
to (k, v)
produces
Some(v1)
. Elements that produce None
are discarded.
def filterWithKey(f: k -> (v -> Bool \ ef), m: Map[k, v]): Map[k, v] \ ef
SourceReturns a map of all mappings k => v
in m
where (k, v)
satisfies the predicate f
.
def findLeft(f: k -> (v -> Bool \ ef), m: Map[k, v]): Option[(k, v)] \ ef
SourceOptionally returns the first mapping of m
that satisfies the predicate f
when searching from left to right.
def findRight(f: k -> (v -> Bool \ ef), m: Map[k, v]): Option[(k, v)] \ ef
SourceOptionally returns the first mapping of m
that satisfies the predicate f
when searching from right to left.
def foldLeft(f: b -> (v -> b \ ef), s: b, m: Map[k, v]): b \ ef
SourceApplies f
to a start value s
and all values in m
going from left to right.
That is, the result is of the form: f(...f(f(s, v1), v2)..., vn)
.
def foldLeftWithKey(f: b -> (k -> (v -> b \ ef)), s: b, m: Map[k, v]): b \ ef
SourceApplies f
to a start value s
and all key-value pairs in m
going from left to right.
That is, the result is of the form: f(...f(f(s, k1, v1), k2, v2)..., vn)
.
def foldMap(f: v -> b \ ef, m: Map[k, v]): b \ ef
SourceReturns the result of mapping each value and combining the results.
def foldMapWithKey(f: k -> (v -> b \ ef), m: Map[k, v]): b \ ef
SourceReturns the result of mapping each key-value pair and combining the results.
def foldRight(f: v -> (b -> b \ ef), s: b, m: Map[k, v]): b \ ef
SourceApplies f
to a start value s
and all values in 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: Map[k, v]): b \ ef
SourceApplies f
to a start value z
and all values in 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: Map[k, v]): b \ ef
SourceApplies f
to a start value s
and all key-value pairs in 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: Map[k, v]): b \ ef
SourceApplies f
to a start value z
and all key-value pairs in 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)), s: b, m: Map[k, v]): b \ ef
SourceAlias for foldLeftWithKey
.
@ParallelWhenPure
def forAll(f: k -> (v -> Bool \ ef), m: Map[k, v]): Bool \ ef
SourceReturns true
if and only if all mappings in m
satisfy the predicate f
.
Returns true
if m
is the empty map.
Purity reflective: Runs in parallel when given a pure function f
.
def forEach(f: k -> (v -> Unit \ ef), m: Map[k, v]): Unit \ ef
SourceApplies f
to every (key, value)
of m
.
def forEachWithIndex(f: Int32 -> (k -> (v -> Unit \ ef)), m: Map[k, v]): Unit \ ef
SourceApplies f
to tuple (index, key, value)
formed of the keys and values of
Map m
and the index of the traversal.
def get(k: k, m: Map[k, v]): Option[v]
SourceReturns Some(v)
if k => v
is in m
.
Otherwise returns None
.
def getWithDefault(k: k, d: v, m: Map[k, v]): v
SourceReturns v
if k => v
is in m
.
Otherwise, returns d
.
def insertWith(f: v -> (v -> v \ ef), k: k, v: v, m: Map[k, v]): Map[k, v] \ ef
SourceUpdates m
with k => f(v, v1)
if k => v1
is in m
.
Otherwise, updates m
with k => v
.
def insertWithKey(f: k -> (v -> (v -> v \ ef)), k: k, v: v, m: Map[k, v]): Map[k, v] \ ef
SourceUpdates m
with k => f(k, v, v1)
if k => v1
is in m
.
Otherwise, updates m
with k => v
.
def intersection(m1: Map[k, v], m2: Map[k, v]): Map[k, v]
SourceReturns the left-biased intersection of m1
and m2
.
That is, key collisions are resolved by taking the mapping from m1
.
def intersectionWith(f: v1 -> (v2 -> v3 \ ef), m1: Map[k, v1], m2: Map[k, v2]): Map[k, v3] \ ef
SourceReturns the intersection of m1
and m2
where key collisions are resolved with the merge function f
.
def intersectionWithKey(f: k -> (v1 -> (v2 -> v3 \ ef)), m1: Map[k, v1], m2: Map[k, v2]): Map[k, v3] \ ef
SourceReturns the intersection of m1
and m2
where key collisions are resolved with the merge function f
, taking both the key and values.
def invert(m: Map[k, v]): Map[v, Set[k]]
SourceReturns the inverse map of m
.
That is, given a Map[k, v]
returns a map Map[v, Set[k]]
where every value is mapped to its key(s) in the original map.
def isProperSubmapOf(m1: Map[k, v], m2: Map[k, v]): Bool
SourceReturns true
if and only if all mappings in m1
occur in m2
and m1 != m2
.
def isSubmapOf(m1: Map[k, v], m2: Map[k, v]): Bool
SourceReturns true
if and only if all mappings in m1
occur in m2
.
def iterator(rc: Region[r], m: Map[k, v]): Iterator[(k, v), r, r] \ r
SourceReturns an iterator over all key-value pairs in m
.
def iteratorKeys(rc: Region[r], m: Map[k, v]): Iterator[k, r, r] \ r
SourceReturns an iterator over keys in m
.
def iteratorValues(rc: Region[r], m: Map[k, v]): Iterator[v, r, r] \ r
SourceReturns an iterator over values in m
.
def joinKeys(sep: String, m: Map[k, v]): String
SourceReturns the concatenation of the string representation of each key k
in m
with sep
inserted between each element.
def joinValues(sep: String, m: Map[k, v]): String
SourceReturns 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: Map[k, v]): String \ ef
SourceReturns the concatenation of the string representation of each key-value pair
k => v
in m
according to f
with sep
inserted between each element.
@ParallelWhenPure
def map(f: v1 -> v2 \ ef, m: Map[k, v1]): Map[k, v2] \ ef
SourceReturns a map with mappings k => f(v)
for every k => v
in m
.
Purity reflective: Runs in parallel when given a pure function f
.
@ParallelWhenPure
def mapWithKey(f: k -> (v1 -> v2 \ ef), m: Map[k, v1]): Map[k, v2] \ ef
SourceReturns 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: Map[k, v]): Option[(k, v)]
SourceOptionally finds k => v
where k
is the largest key according to the Order
instance of k
.
Returns None
if m
is empty.
@ParallelWhenPure
def maximumKeyBy(cmp: k -> (k -> Comparison \ ef), m: Map[k, v]): Option[(k, v)] \ ef
SourceOptionally 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 cmp
.
@Parallel
def maximumValue(m: Map[k, v]): Option[(k, v)]
SourceOptionally finds k => v
where v
is the largest value.
Returns None
if m
is empty.
@ParallelWhenPure
def maximumValueBy(cmp: v -> (v -> Comparison \ ef), m: Map[k, v]): Option[(k, v)] \ ef
SourceOptionally 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 minimumKey(m: Map[k, v]): Option[(k, v)]
SourceOptionally finds k => v
where k
is the smallest key according to the Order
instance of k
.
Returns None
if m
is empty.
@ParallelWhenPure
def minimumKeyBy(cmp: k -> (k -> Comparison \ ef), m: Map[k, v]): Option[(k, v)] \ ef
SourceOptionally 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: Map[k, v]): Option[(k, v)]
SourceOptionally finds k => v
where v
is the smallest value.
Returns None
if m
is empty.
@ParallelWhenPure
def minimumValueBy(cmp: v -> (v -> Comparison \ ef), m: Map[k, v]): Option[(k, v)] \ ef
SourceOptionally 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 query(p: k -> Comparison \ ef, m: Map[k, v]): List[(k, v)] \ ef
SourceExtracts a range of key-value pairs from the map m
.
That is, the result is a list of all pairs (k, v)
where p(k)
returns Equal
.
def queryWith(p: k -> Comparison \ ef1, f: k -> (v -> Unit \ ef2), m: Map[k, v]): Unit \ ef1 + ef2
SourceApplies f
to all key-value pairs (k, v)
from the map m
where p(k)
returns EqualTo
.
def reduceLeft(f: v -> (v -> v \ ef), m: Map[k, v]): Option[v] \ ef
SourceApplies f
to all values in 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: Map[k, v]): Option[(k, v)] \ ef
SourceApplies f
to all mappings in 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: Map[k, v]): Option[v] \ ef
SourceApplies f
to all values in 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: Map[k, v]): Option[(k, v)] \ ef
SourceApplies f
to all mappings in 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 sequence(m: Map[k, m[v]]): m[Map[k, v]]
SourceReturns the result of running all the actions in the map m
.
def singleton(k: k, v: v): Map[k, v]
SourceReturns the singleton map where key k
is mapped to value v
.
Map#{k => v}
is syntactic sugar for singleton
(Map#{k => v} = singleton(k, v)
).
@ParallelWhenPure
def sumWith(f: k -> (v -> Int32 \ ef), m: Map[k, v]): Int32 \ ef
SourceReturns 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 toDelayList(m: Map[k, v]): DelayList[(k, v)]
SourceReturns the map m
as a DelayList
of key-value pairs.
def toMultiMap(m: Map[k, v]): MultiMap[k, v]
SourceReturns a MultiMap where key k
is mapped to the singleton set containing v
.
def traverse(f: v1 -> m[v2] \ ef, m: Map[k, v1]): m[Map[k, v2]] \ ef
SourceReturns the result of applying the applicative mapping function f
to all the values of the
map m
.
def traverseWithKey(f: k -> (v1 -> m[v2] \ ef), m: Map[k, v1]): m[Map[k, v2]] \ ef
SourceReturns the result of applying the applicative mapping function f
to all the key-value pairs
of the map m
.
def unfold(f: s -> Option[(k, v, s)] \ ef, st: s): Map[k, v] \ ef
SourceBuild a map by applying f
to the seed value st
.
f
should return Some(k,v,st1)
to signal a new key-value pair k
and v
and a new seed value st1
.
f
should return None
to signal the end of building the map.
def unfoldWithIter(next: Unit -> Option[(k, v)] \ ef): Map[k, v] \ ef
SourceBuild a map by applying the function next
to ()
. next
is expected to encapsulate
a stateful resource such as a file handle that can be iterated.
next
should return Some(k,v)
to signal a new key-value pair k
and v
.
next
should return None
to signal the end of building the map.
def union(m1: Map[k, v], m2: Map[k, v]): Map[k, v]
SourceReturns the left-biased union of m1
and m2
.
That is, key collisions are resolved by taking the mapping from m1
.
def unionWith(f: v -> (v -> v \ ef), m1: Map[k, v], m2: Map[k, v]): Map[k, v] \ ef
SourceReturns the union of m1
and m2
where key collisions are resolved with the merge function f
.
def unionWithKey(f: k -> (v -> (v -> v \ ef)), m1: Map[k, v], m2: Map[k, v]): Map[k, v] \ ef
SourceReturns the union of m1
and m2
where key collisions are resolved with the merge function f
, taking both the key and values.
def update(f: v -> Option[v] \ ef, k: k, m: Map[k, v]): Map[k, v] \ ef
SourceUpdates m
with k => v1
if k => v
is in m
and f(v) = Some(v1)
. Otherwise, returns m
.
def updateWithKey(f: k -> (v -> Option[v] \ ef), k: k, m: Map[k, v]): Map[k, v] \ ef
SourceUpdates m
with k => v1
if k => v
is in m
and f(k, v) = Some(v1)
. Otherwise, returns m
.