tiinvo

tiinvo / Exports / TypedMap

Namespace: TypedMap

Table of contents

Type Aliases

Factories

Guardables

Comparables

Accessors

Operators

Type Aliases

T

Ƭ 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

Type parameters

Name Description
K the key type of the TypedMap
V the value type of the TypedMap

Type declaration

Name Type
[guardsymbolKey] Guardable<K>
[guardsymbolValue] Guardable<V>
[valuessymbol] Map<K, V>
[iterator] () => Iterator<readonly [K, V], any, undefined>

Defined in

src/TypedMap.ts:26

Factories

make

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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Default value
kg Guardable<K> | GuardableModule<K> undefined
vg Guardable<V> | GuardableModule<V> undefined
entries Iterable<readonly [K, V]> []

Returns

T<K, V>

the TypedMap.T<K, V>

Defined in

src/TypedMap.ts:61

Guardables

guard

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

Parameters

Name Type Description
x unknown the value to check

Returns

x is T<unknown, unknown>

Defined in

src/TypedMap.ts:143


guardOf

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

Type parameters

Name
K
V

Parameters

Name Type
kg Guardable<K> | GuardableModule<K>
vg Guardable<V> | GuardableModule<V>
x unknown

Returns

x is T<K, V>

Defined in

src/TypedMap.ts:164

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

Type parameters

Name
K
V

Parameters

Name Type
kg Guardable<K> | GuardableModule<K>
vg Guardable<V> | GuardableModule<V>

Returns

fn

the unary function which returns

▸ (x): x is T<K, V>

Parameters
Name Type
x unknown
Returns

x is T<K, V>

Defined in

src/TypedMap.ts:201

Comparables

cmp

cmp<K, V>(kmod, vmod, a, b): ComparableResult

Compares two TypedMaps 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

Type parameters

Name Description
K the key type
V the value type

Parameters

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

Returns

ComparableResult

Defined in

src/TypedMap.ts:272

cmp<K, V>(kmod, vmod, a): Unary<T<K, V>, ComparableResult>

Returns a unary function which compares two TypedMaps 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

Type parameters

Name Description
K the key type
V the value type

Parameters

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

Returns

Unary<T<K, V>, ComparableResult>

the unary function which returns

Defined in

src/TypedMap.ts:303

cmp<K, V>(kmod, vmod): Binary<T<K, V>, T<K, V>, ComparableResult>

Returns a binary function which compares two TypedMaps 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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Description
kmod Comparable<K> | ComparableModule<K> the key comparer
vmod Comparable<V> | ComparableModule<V> the value comparer

Returns

Binary<T<K, V>, T<K, V>, ComparableResult>

the binary function which returns

Defined in

src/TypedMap.ts:334


eq

eq<K, V>(kmod, vmod, a, b): boolean

Compares two TypedMaps 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

Type parameters

Name Description
K the key type
V the value type

Parameters

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

Returns

boolean

Defined in

src/TypedMap.ts:390

eq<K, V>(kmod, vmod, a): Unary<T<K, V>, boolean>

Returns a unary function which compares two TypedMaps 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

Type parameters

Name Description
K the key type
V the value type

Parameters

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

Returns

Unary<T<K, V>, boolean>

the unary function which returns

Defined in

src/TypedMap.ts:420

eq<K, V>(kmod, vmod): Binary<T<K, V>, T<K, V>, boolean>

Returns a binary function which compares two TypedMaps 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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Description
kmod Comparable<K> | ComparableModule<K> the key comparer
vmod Comparable<V> | ComparableModule<V> the value comparer

Returns

Binary<T<K, V>, T<K, V>, boolean>

the binary function which returns

Defined in

src/TypedMap.ts:450

Accessors

entries

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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Description
t T<K, V> the TypedMap

Returns

IterableIterator<[K, V]>

t entries

Defined in

src/TypedMap.ts:494


get

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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Description
key K the key
t T<K, V> the TypedMap

Returns

T<V>

Defined in

src/TypedMap.ts:521

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

Type parameters

Name Description
K the key type

Parameters

Name Type Description
key K the key

Returns

fn

▸ <V>(t): T<V>

Type parameters
Name
V
Parameters
Name Type
t T<K, V>
Returns

T<V>

Defined in

src/TypedMap.ts:545


has

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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Description
key K the key
t T<K, V> the TypedMap

Returns

boolean | never

Defined in

src/TypedMap.ts:580

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

Type parameters

Name Description
K the key type
V -

Parameters

Name Type Description
key K the key

Returns

fn

the unary function which accepts a TypedMap and returns

▸ <V>(t): boolean | never

Type parameters
Name
V
Parameters
Name Type
t T<K, V>
Returns

boolean | never

Defined in

src/TypedMap.ts:604


keys

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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Description
t T<K, V> the TypedMap

Returns

IterableIterator<K>

the keys iterable

Defined in

src/TypedMap.ts:645


size

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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Description
t T<K, V> the TypedMap

Returns

number

the TypedMap’s size

Defined in

src/TypedMap.ts:667


values

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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Description
t T<K, V> the TypedMap

Returns

IterableIterator<V>

the keys iterable

Defined in

src/TypedMap.ts:689

Operators

delete

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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Description
key K the key
t T<K, V> the TypedMap

Returns

T<K, V>

the new TypedMap

Defined in

src/TypedMap.ts:717

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

Type parameters

Name Description
K the key type

Parameters

Name Type Description
key K the key

Returns

fn

the unary function which deletes the key and returns the new TypedMap

▸ <V>(t): T<K, V>

Type parameters
Name
V
Parameters
Name Type
t T<K, V>
Returns

T<K, V>

Defined in

src/TypedMap.ts:740


set

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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Description
a K the key
b V the value
c T<K, V> the TypedMap

Returns

T<K, V>

the new TypedMap

Defined in

src/TypedMap.ts:797

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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Description
a K the key
b V the value

Returns

Unary<T<K, V>, T<K, V>>

the unary function

Defined in

src/TypedMap.ts:823

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

Type parameters

Name Description
K the key type
V the value type

Parameters

Name Type Description
a T<K, V> the key

Returns

Binary<K, V, T<K, V>>

the unary function

Defined in

src/TypedMap.ts:850