The iiris/map module includes functions for working with Maps. It is
designed to be imported with a wildcard, e.g.
import * as M from 'iiris/map'<K, V>() => Map<K, V>Create an empty map.
M.empty()
// => Map(0) {}See also: singleton
<K, V>(map: Map<K, V>) => IterableIterator<[K, V]>Return a new iterator containing the key-value pairs of the map in insertion order.
M.entries()
// => [Map Entries] { [ 'a', 1 ] }<K, V>(fn: (key: K, value: V) => void) => (map: Map<K, V>) => Map<K, V>Apply a fn to each key-value pair of the map.
M.forEach((k, v) => {
conso
}, map)<K, V>(entries: Iterable<[K, V]>) => Map<K, V>Create a map from an array of [key, value] pairs.
M.fromEntries([
['a', 1],
['b', 2],
['c', 3],
])
// => Map(3) { 'a' => 1, 'b' => 2, 'c' => 3 }See also: entries
<K extends string, V>(object: Record<K, V>) => Map<K, V>Convert an object to a map.
M.fromObject({ a: 1, b: 2, c: 3 })
// => Map(3) { 'a' => 1, 'b' => 2, 'c' => 3 }<K>(key: K) => <V>(map: Map<K, V>) => V | undefinedRetrieve the specified value from the map.
M.get('a', M.singleton('a', 1))
// => 1
M.get('b', M.singleton('a', 1))
// => undefinedSee also: getOr
<V>(defaultValue: V) => <K>(key: K) => (map: Map<K, V>) => VRetrieve the specified value or defaultValue from the map.
M.getOr(999, 'a', M.singleton('a', 1))
// => 1
M.getOr(999, 'b', M.singleton('a', 1))
// => 999<K>(key: K) => <V>(map: Map<K, V>) => booleanCheck if map contains the specified key.
M.has('a', M.singleton('a', 1))
// => true<K, V>(map: Map<K, V>) => booleanCheck if the map is empty.
M.isEmpty(M.empty())
// => true<K, V>(map: Map<K, V>) => IterableIterator<K>Return a new iterator containing the keys of the map in insertion order.
M.keys(M.singleton('a', 1))
// => [Map Iterator] { 'a' }<V1, V2>(fn: (value: V1) => V2) => <K>(map: Map<K, V1>) => Map<K, V2>Return a map containing the results of applying fn to each value of the
original map.
M.map((n) => n + 1, M.fromObject({ a: 1, b: 2, c: 3 }))
// => Map(3) { 'a' => 2, 'b' => 3, 'c' => 4 }See also: mapKeys
<K1, K2>(fn: (key: K1) => K2) => <V>(map: Map<K1, V>) => Map<K1, V>Return a map containing the results of applying fn to each key of the
original map.
M.mapKeys((k) => k.toUpperCase(), M.fromObject({ a: 1, b: 2, c: 3 }))
// => Map(3) { 'A' => 1, 'B' => 2, 'C' => 3 }See also: mapKeys
<K>(key: K) => <V>(fn: (value: V) => V) => (map: Map<K, V>) => Map<K, V>Return a copy of map where key has been replaced by applying fn to its
current value.
- If the
mapdoesn't containkey, it is returned unchanged.
M.modify('a', (n) => n + 1, M.singleton('a', 1))
// => Map(1) { 'a' => 2 }<K>(key: K) => <V>(map: Map<K, V>) => Map<K, V>Return a copy of map without the specified key.
M.remove('a', M.singleton('a', 1))
// => Map(2) { 'a' => 1, 'b' => 2 }<K>(key: K) => <V>(value: V) => (map: Map<K, V>) => Map<K, V>Return a copy of map with key set to value.
M.set('b', 2, M.singleton('a', 1))
// => Map(2) { 'a' => 1, 'b' => 2 }<K>(key: K) => <V>(value: V) => Map<K, V>Create a map with a single element.
M.singleton('a', 1)
// => Map(1) { 'a' => 1 }See also: singleton
<K, V>(map: Map<K, V>) => numberReturn the number of entries in the map.
M.size(M.singleton('a', 1)
// => 1<K, V>(map: Map<K, V>) => IterableIterator<V>Return a new iterator containing the values of the map in insertion order.
M.values(M.singleton('a', 1))
// => [Map Iterator] { 1 }