Ƭ T<K
, V
>: Object
Represents a TypedMap<K, V>
.
Example
import { TypedMap, Num, Str } from 'tiinvo'
const tm0 = TypedMap.make(Num, Str)
const tm1 = TypedMap.make(Num, Str, [[10, "hello"], [20, "world"]])
Since
4.0.0
Name | Description |
---|---|
K |
the key type of the TypedMap |
V |
the value type of the TypedMap |
Name | Type |
---|---|
[guardsymbolKey] |
Guardable <K > |
[guardsymbolValue] |
Guardable <V > |
[valuessymbol] |
Map <K , V > |
[iterator] |
() => Iterator <readonly [K , V ], any , undefined > |
▸ make<K
, V
>(kg
, vg
, entries?
): T
<K
, V
>
Creates a new TypedMap.T<K, V>
.
Example
import { Str, Num, TypedMap } from 'tiinvo'
const m = new Map<string, number>([['hello', 100], ['world', 200]])
TypedMap.make(Str, Num)
TypedMap.make(Str, Num, m)
TypedMap.make(Str.guard, Num)
TypedMap.make(Str.guard, Num, m)
TypedMap.make(Str, Num.guard)
TypedMap.make(Str, Num.guard, m)
TypedMap.make(Str.guard, Num.guard)
TypedMap.make(Str.guard, Num.guard, m)
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Default value |
---|---|---|
kg |
Guardable <K > | GuardableModule <K > |
undefined |
vg |
Guardable <V > | GuardableModule <V > |
undefined |
entries |
Iterable <readonly [K , V ]> |
[] |
T
<K
, V
>
the TypedMap.T<K, V>
▸ guard(x
): x is T<unknown, unknown>
Checks if x
is a TypedMap.T<unknown, unknown>
Example
import { TypedMap, Num, Str } from 'tiinvo'
TypedMap.guard(10) // false
TypedMap.guard({}) // false
TypedMap.guard(TypedMap.make(Num, Str)) // true
Since
4.0.0
Name | Type | Description |
---|---|---|
x |
unknown |
the value to check |
x is T<unknown, unknown>
true
if x
is a TypedMap.T<unknown, unknown>
false
otherwise▸ guardOf<K
, V
>(kg
, vg
, x
): x is T<K, V>
Checks if x
is of type T<K, V>
Example
import { TypedMap, Str, Num } from 'tiinvo'
TypedMap.guardOf(Str, Num, 10) // false
TypedMap.guardOf(Str, Num, TypedMap.make(Str, Num, [["hello", 10]])) // true
TypedMap.guardOf(Num, Num, TypedMap.make(Str, Num, [["hello", 10]])) // false
Since
4.0.0
Name |
---|
K |
V |
Name | Type |
---|---|
kg |
Guardable <K > | GuardableModule <K > |
vg |
Guardable <V > | GuardableModule <V > |
x |
unknown |
x is T<K, V>
true
if x
is a TypedMap.T<K, V>
false
otherwise▸ guardOf<K
, V
>(kg
, vg
): (x
: unknown
) => x is T<K, V>
Returns a unary function which checks if x
is of type T<K, V>
Example
import { TypedMap, Str, Num } from 'tiinvo'
const guard0 = TypedMap.guardOf(Str, Num);
const guard1 = TypedMap.guardOf(Str.guard, Num);
const guard2 = TypedMap.guardOf(Str, Num.guard);
const guard3 = TypedMap.guardOf(Str.guard, Num.guard);
const m1 = TypedMap.make(Str, Num, [["hello", 10]]);
const m2 = TypedMap.make(Num, Str, [[10, "hello"]]);
guard0(10) // false
guard0(m1) // true
guard0(m2) // false
guard1(10) // false
guard1(m1) // true
guard1(m2) // false
guard2(10) // false
guard2(m1) // true
guard2(m2) // false
guard3(10) // false
guard3(m1) // true
guard3(m2) // false
Since
4.0.0
Name |
---|
K |
V |
Name | Type |
---|---|
kg |
Guardable <K > | GuardableModule <K > |
vg |
Guardable <V > | GuardableModule <V > |
fn
the unary function which returns
true
if x
is a TypedMap.T<K, V>
false
otherwise▸ (x
): x is T<K, V>
Name | Type |
---|---|
x |
unknown |
x is T<K, V>
▸ cmp<K
, V
>(kmod
, vmod
, a
, b
): ComparableResult
Compares two TypedMap
s with a key comparer and a value comparer
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m0 = TypedMap.make(Str, Num, [["a", 1], ["b", 2]])
const m1 = TypedMap.make(Str, Num, [["a", 1]])
const m2 = TypedMap.make(Str, Num, [["a", 1], ["b", 2]])
const m3 = TypedMap.make(Str, Num, [["b", 1], ["c", 2]])
TypedMap.cmp(Str, Num, m0, m1) // 1
TypedMap.cmp(Str, Num, m0, m2) // 0
TypedMap.cmp(Str, Num, m0, m3) // -1
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
kmod |
Comparable <K > | ComparableModule <K > |
the key comparer |
vmod |
Comparable <V > | ComparableModule <V > |
the value comparer |
a |
T <K , V > |
the first TypedMap |
b |
T <K , V > |
the second TypedMap |
a
is less than b
a
is equal to b
a
is greater than b
▸ cmp<K
, V
>(kmod
, vmod
, a
): Unary
<T
<K
, V
>, ComparableResult
>
Returns a unary function which compares two TypedMap
s with a key comparer and a value comparer
Example
import { TypedMap, Str, Num } from 'tiinvo'
const cmp = TypedMap.cmp(Str, Num, TypedMap.make(Str, Num, [["a", 1], ["b", 2]]))
const m1 = TypedMap.make(Str, Num, [["a", 1]])
const m2 = TypedMap.make(Str, Num, [["a", 1], ["b", 2]])
const m3 = TypedMap.make(Str, Num, [["b", 1], ["c", 2]])
cmp(m1) // -1
cmp(m2) // 0
cmp(m3) // 1
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
kmod |
Comparable <K > | ComparableModule <K > |
the key comparer |
vmod |
Comparable <V > | ComparableModule <V > |
the value comparer |
a |
T <K , V > |
the first TypedMap |
Unary
<T
<K
, V
>, ComparableResult
>
the unary function which returns
b
is less than a
b
is equal to a
b
is greater than a
▸ cmp<K
, V
>(kmod
, vmod
): Binary
<T
<K
, V
>, T
<K
, V
>, ComparableResult
>
Returns a binary function which compares two TypedMap
s with a key comparer and a value comparer
Example
import { TypedMap, Str, Num } from 'tiinvo'
const cmp = TypedMap.cmp(Str, Num)
const m0 = TypedMap.make(Str, Num, [["a", 1], ["b", 2]]);
const m1 = TypedMap.make(Str, Num, [["a", 1]])
const m2 = TypedMap.make(Str, Num, [["a", 1], ["b", 2]])
const m3 = TypedMap.make(Str, Num, [["b", 1], ["c", 2]])
cmp(m0, m1) // 1
cmp(m0, m2) // 0
cmp(m0, m3) // -1
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
kmod |
Comparable <K > | ComparableModule <K > |
the key comparer |
vmod |
Comparable <V > | ComparableModule <V > |
the value comparer |
Binary
<T
<K
, V
>, T
<K
, V
>, ComparableResult
>
the binary function which returns
a
is less than b
a
is equal to b
a
is greater than b
▸ eq<K
, V
>(kmod
, vmod
, a
, b
): boolean
Compares two TypedMap
s with a key comparer and a value comparer
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m0 = TypedMap.make(Str, Num, [["a", 1], ["b", 2]])
const m1 = TypedMap.make(Str, Num, [["a", 1]])
const m2 = TypedMap.make(Str, Num, [["a", 1], ["b", 2]])
const m3 = TypedMap.make(Str, Num, [["b", 1], ["c", 2]])
TypedMap.eq(Str, Num, m0, m1) // false
TypedMap.eq(Str, Num, m0, m2) // true
TypedMap.eq(Str, Num, m0, m3) // false
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
kmod |
Comparable <K > | ComparableModule <K > |
the key comparer |
vmod |
Comparable <V > | ComparableModule <V > |
the value comparer |
a |
T <K , V > |
the first TypedMap |
b |
T <K , V > |
the second TypedMap |
boolean
true
if a
is equal to b
false
otherwise▸ eq<K
, V
>(kmod
, vmod
, a
): Unary
<T
<K
, V
>, boolean
>
Returns a unary function which compares two TypedMap
s with a key comparer and a value comparer
Example
import { TypedMap, Str, Num } from 'tiinvo'
const eq = TypedMap.eq(Str, Num, TypedMap.make(Str, Num, [["a", 1], ["b", 2]]))
const m1 = TypedMap.make(Str, Num, [["a", 1]])
const m2 = TypedMap.make(Str, Num, [["a", 1], ["b", 2]])
const m3 = TypedMap.make(Str, Num, [["b", 1], ["c", 2]])
eq(m1) // false
eq(m2) // true
eq(m3) // false
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
kmod |
Comparable <K > | ComparableModule <K > |
the key comparer |
vmod |
Comparable <V > | ComparableModule <V > |
the value comparer |
a |
T <K , V > |
the first TypedMap |
the unary function which returns
true
if a
is equal to b
false
otherwise▸ eq<K
, V
>(kmod
, vmod
): Binary
<T
<K
, V
>, T
<K
, V
>, boolean
>
Returns a binary function which compares two TypedMap
s with a key comparer and a value comparer
Example
import { TypedMap, Str, Num } from 'tiinvo'
const eq = TypedMap.eq(Str, Num)
const m0 = TypedMap.make(Str, Num, [["a", 1], ["b", 2]]);
const m1 = TypedMap.make(Str, Num, [["a", 1]])
const m2 = TypedMap.make(Str, Num, [["a", 1], ["b", 2]])
const m3 = TypedMap.make(Str, Num, [["b", 1], ["c", 2]])
eq(m0, m1) // false
eq(m0, m2) // true
eq(m0, m3) // false
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
kmod |
Comparable <K > | ComparableModule <K > |
the key comparer |
vmod |
Comparable <V > | ComparableModule <V > |
the value comparer |
Binary
<T
<K
, V
>, T
<K
, V
>, boolean
>
the binary function which returns
true
if a
is equal to b
false
otherwise▸ entries<K
, V
>(t
): IterableIterator
<[K
, V
]>
Returns an iterable of key, value pairs for every entry in the map.
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m = TypedMap.make(Str, Num, [['a', 100], ['b', 200]])
for (const [k, v] of TypedMap.entries(m)) {
console.log(k, v)
}
// logs
// 'a' 100
// 'b' 200
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
t |
T <K , V > |
the TypedMap |
IterableIterator
<[K
, V
]>
t entries
▸ get<K
, V
>(key
, t
): T
<V
>
Gets a value Option.T<V>
stored with a key K
Example
import { TypedMap, Str, Num } from 'tiinvo'
const foo = TypedMap.make(Str, Num, [['a', 1], ['b', 2]])
TypedMap.get("a") // 1
TypedMap.get("b") // 2
TypedMap.get("c") // null
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
key |
K |
the key |
t |
T <K , V > |
the TypedMap |
T
<V
>
Option.Some<V>
Option.None
otherwise▸ get<K
>(key
): <V>(t
: T
<K
, V
>) => T
<V
>
Returns a unary function which gets a value Option.T<V>
stored with a key K
Example
import { TypedMap, Str, Num } from 'tiinvo'
const foo = TypedMap.make(Str, Num, [['a', 1], ['b', 2]])
const getA = TypedMap.get("a")
const getB = TypedMap.get("b")
const getC = TypedMap.get("c")
getA(foo) // 1
getB(foo) // 2
getC(foo) // null
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
Name | Type | Description |
---|---|---|
key |
K |
the key |
fn
▸ <V
>(t
): T
<V
>
Name |
---|
V |
Name | Type |
---|---|
t |
T <K , V > |
T
<V
>
▸ has<K
, V
>(key
, t
): boolean
| never
Checks if a TypedMap has a key K
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m = TypedMap.make(Str, Num, [["hello", 100]])
TypedMap.has("hello", m) // true
TypedMap.has("world", m) // false
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
key |
K |
the key |
t |
T <K , V > |
the TypedMap |
boolean
| never
true
if the TypedMap has a key K
false
otherwise▸ has<K
, V
>(key
): <V>(t
: T
<K
, V
>) => boolean
| never
Returns a unary function which checks if a TypedMap has a key K
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m = TypedMap.make(Str, Num, [["hello", 100]])
const hasHello = TypedMap.has("hello")
hasHello(m) // true
hasHello(m) // false
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
- |
Name | Type | Description |
---|---|---|
key |
K |
the key |
fn
the unary function which accepts a TypedMap and returns
true
if the TypedMap has a key K
false
otherwise▸ <V
>(t
): boolean
| never
Name |
---|
V |
Name | Type |
---|---|
t |
T <K , V > |
boolean
| never
▸ keys<K
, V
>(t
): IterableIterator
<K
>
Returns an iterable of keys in the map
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m = TypedMap.make(Str, Num, [["a", 1], ["b", 2]])
Array.from(TypedMap.keys(m)) // ["a", "b"]
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
t |
T <K , V > |
the TypedMap |
IterableIterator
<K
>
the keys iterable
▸ size<K
, V
>(t
): number
Returns the number of elements in the Map
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m = TypedMap.make(Str, Num, [["a", 1], ["b", 2]])
TypedMap.size(m) // 2
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
t |
T <K , V > |
the TypedMap |
number
the TypedMap’s size
▸ values<K
, V
>(t
): IterableIterator
<V
>
Returns an iterable of values in the map
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m = TypedMap.make(Str, Num, [["a", 1], ["b", 2]])
Array.from(TypedMap.values(m)) // [1, 2]
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
t |
T <K , V > |
the TypedMap |
IterableIterator
<V
>
the keys iterable
▸ delete<K
, V
>(key
, t
): T
<K
, V
>
Removes an entry K
from a TypedMap T<K, V>
if any and returns a new TypedMap
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m0 = TypedMap.make(Str, Num, [['a', 0], ['b', 1]])
const m1 = TypedMap.delete('a', m0)
TypedMap.keys(m1) // ['b']
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
key |
K |
the key |
t |
T <K , V > |
the TypedMap |
T
<K
, V
>
the new TypedMap
▸ delete<K
>(key
): <V>(t
: T
<K
, V
>) => T
<K
, V
>
Returns a unary function which removes an entry K
from a TypedMap T<K, V>
if any and returns a new TypedMap
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m0 = TypedMap.make(Str, Num, [['a', 0], ['b', 1]])
const m1 = TypedMap.make(Str, Num, [['a', 0], ['c', 1]])
const deleteA = TypedMap.delete("a")
TypedMap.keys(deleteA(m0)) // ['b']
TypedMap.keys(deleteA(m1)) // ['c']
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
Name | Type | Description |
---|---|---|
key |
K |
the key |
fn
the unary function which deletes the key and returns the new TypedMap
▸ <V
>(t
): T
<K
, V
>
Name |
---|
V |
Name | Type |
---|---|
t |
T <K , V > |
T
<K
, V
>
▸ set<K
, V
>(a
, b
, c
): T
<K
, V
>
Sets a new value V
at the key K
for a TypedMap T<K, V>
.
This will not mutate the original map and will return a new TypedMap T<K, V>
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m0 = TypedMap.make(Str, Num)
const m1 = TypedMap.set("hello", 100, m0)
Array.from(TypedMap.values(m0)) // []
Array.from(TypedMap.values(m1)) // [100]
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
a |
K |
the key |
b |
V |
the value |
c |
T <K , V > |
the TypedMap |
T
<K
, V
>
the new TypedMap
▸ set<K
, V
>(a
, b
): Unary
<T
<K
, V
>, T
<K
, V
>>
Returns a unary function which sets a new value V
at the key K
for a TypedMap T<K, V>
.
This will not mutate the original map and will return a new TypedMap T<K, V>
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m0 = TypedMap.make(Str, Num)
const setHello = TypedMap.set("hello", 100);
Array.from(TypedMap.values(setHello(m1))) // [100]
Array.from(TypedMap.values(m0)) // []
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
a |
K |
the key |
b |
V |
the value |
the unary function
▸ set<K
, V
>(a
): Binary
<K
, V
, T
<K
, V
>>
Returns a binary function which sets a new value V
at the key K
for a TypedMap T<K, V>
.
This will not mutate the original map and will return a new TypedMap T<K, V>
Example
import { TypedMap, Str, Num } from 'tiinvo'
const m0 = TypedMap.make(Str, Num)
const set = TypedMap.set(m0);
Array.from(TypedMap.values(set("hello", 100))) // [100]
Array.from(TypedMap.values(set("world", 200))) // [200]
Array.from(TypedMap.values(m0)) // []
Since
4.0.0
Name | Description |
---|---|
K |
the key type |
V |
the value type |
Name | Type | Description |
---|---|---|
a |
T <K , V > |
the key |
the unary function