class ContextBase<UK,Tp>
undocumented
Implements: RMapBase.Context<UK,Tp>
Extended by: SortedMapContext<UK>
, HashMapContext<UK>
, OrderedMapContextImpl<UK,Tp>
, ProximityMapContext<UK>
Type parameters
Name | Constraints | Default | Description |
---|---|---|---|
UK | undocumented | ||
Tp | RMapBase.Types | RMapBase.Types | undocumented |
Properties
_fixedKeyType
undocumented
_fixedKeyType
_types
undocumented
_types
builder
undocumented
builder
Definition
abstract builder: <K extends UK, V>() =>
WithKeyValue
<Tp, K, V>['builder'];
empty
undocumented
empty
Definition
readonly empty: <K extends UK, V>() =>
WithKeyValue
<Tp, K, V>["normal"];
of
undocumented
of
Definition
readonly of: <K extends UK, V>(values_0: readonly [K, V], ...values_1: (readonly [K, V])[]) => K extends UK ?
WithKeyValue
<Tp, K, V>["nonEmpty"] : never;
reducer
undocumented
reducer
Definition
readonly reducer: <K extends UK, V>(source?:
StreamSource
<readonly [K, V]>) => Reducer<readonly [K, V],
WithKeyValue
<Tp, K, V>["normal"]>;
typeTag
undocumented
typeTag
Methods
builder
Returns an empty builder instance for this type of collection and context.
builder
Definition
builder<K extends UK, V>():
WithKeyValue
<Tp, K, V>['builder'];
Type parameters
Name | Constraints | Description |
---|---|---|
K | UK | |
V |
HashMap.builder<number, string>() // => HashMap.Builder<number, string>
Overrides
empty
Returns the (singleton) empty instance of this type and context with given key and value types.
empty
Definition
empty<K extends UK, V>():
WithKeyValue
<Tp, K, V>['normal'];
Type parameters
Name | Constraints | Description |
---|---|---|
K | UK | |
V |
HashMap.empty<number, string>() // => HashMap<number, string>
HashMap.empty<string, boolean>() // => HashMap<string, boolean>
Overrides
from
Returns an immutable map of this type and context, containing the entries in the given sources
StreamSource
instances.
from
sources
StreamSource
instances.Definitions
from<K extends UK, V>(...sources:
ArrayNonEmpty
<
StreamSource.NonEmpty
<readonly [K, V]>>):
WithKeyValue
<Tp, K, V>['nonEmpty'];
from<K, V>(...sources:
ArrayNonEmpty
<
StreamSource
<readonly [K, V]>>):
WithKeyValue
<Tp, K, V>['normal'];
Type parameters
Name | Constraints | Description |
---|---|---|
K | UK | |
V |
Parameters
Name | Type | Description |
---|---|---|
sources | ArrayNonEmpty < StreamSource.NonEmpty <readonly [K, V]>> | an array of StreamSource instances containing key-value entries |
HashMap.from([[1, 'a'], [2, 'b']]) // => HashMap.NonEmpty<number, string>
Overrides
isNonEmptyInstance
undocumented
isNonEmptyInstance
Definition
abstract isNonEmptyInstance<K, V>(source: any): source is
WithKeyValue
<Tp, K, V>['nonEmpty'];
Type parameters
Name | Description |
---|---|
K | |
V |
Parameters
Name | Type | Description |
---|---|---|
source | any |
isValidKey
undocumented
isValidKey
merge
Returns a Map containing the common keys from this map and all the given sources
key-value stream sources, and as values tuples of all the corresponding values for each common key. If a source doesn't have a key, the key will be skipped.
merge
sources
key-value stream sources, and as values tuples of all the corresponding values for each common key. If a source doesn't have a key, the key will be skipped.Definitions
merge<K extends UK, I extends readonly [unknown, unknown, ...unknown[]]>(...sources: {
[KT in keyof I]:
StreamSource.NonEmpty
<readonly [K, I[KT]]>;
} & unknown[]):
WithKeyValue
<Tp, K, {
[KT in keyof I]: I[KT];
}>['nonEmpty'];
merge<K extends UK, I extends readonly [unknown, unknown, ...unknown[]]>(...sources: {
[KT in keyof I]:
StreamSource
<readonly [K, I[KT]]>;
} & unknown[]):
WithKeyValue
<Tp, K, {
[KT in keyof I]: I[KT];
}>['normal'];
Type parameters
Name | Constraints | Description |
---|---|---|
K | UK | the common key type |
I | readonly [unknown, unknown, ...unknown[]] | the array of input source value types |
Parameters
Name | Type | Description |
---|---|---|
sources | { [KT in keyof I]: StreamSource.NonEmpty <readonly [K, I[KT]]>; } & unknown[] | a non-empty set of StreamSouces containing tuples of keys and values |
const m = HashMap.of([1, 'a'], [2, 'b'])
const m2 = HashMap.merge(m, [[2, true]], HashMap.of([2, 15]))
// type of m2: HashMap<number, [string, boolean, number]>
console.log(m2.toArray())
// => [[2, ['b', true, 15]]]
Overrides
mergeAll
Returns a Map containing all keys from this map and all the given sources
key-value stream sources, and as values tuples of all the corresponding values for each key. If a source doesn't have a key, the tuple will be filled with the given fillValue
.
mergeAll
sources
key-value stream sources, and as values tuples of all the corresponding values for each key. If a source doesn't have a key, the tuple will be filled with the given fillValue
.Definitions
mergeAll<O, I extends readonly [unknown, unknown, ...unknown[]], K extends UK>(fillValue: O, ...sources: {
[KT in keyof I]:
StreamSource.NonEmpty
<readonly [K, I[KT]]>;
} & unknown[]):
WithKeyValue
<Tp, K, {
[KT in keyof I]: I[KT]
|
O;
}>['nonEmpty'];
mergeAll<O, I extends readonly [unknown, unknown, ...unknown[]], K extends UK>(fillValue: O, ...sources: {
[KT in keyof I]:
StreamSource
<readonly [K, I[KT]]>;
} & unknown[]):
WithKeyValue
<Tp, K, {
[KT in keyof I]: I[KT]
|
O;
}>['normal'];
Type parameters
Name | Constraints | Description |
---|---|---|
O | the type of the fill value | |
I | readonly [unknown, unknown, ...unknown[]] | the array of input source value types |
K | UK | the common key type |
Parameters
Name | Type | Description |
---|---|---|
fillValue | O | the value to use for the result tuple if a source does not have a certain key |
sources | { [KT in keyof I]: StreamSource.NonEmpty <readonly [K, I[KT]]>; } & unknown[] | a non-empty set of StreamSouces containing tuples of keys and values |
const m = HashMap.of([1, 'a'], [2, 'b'])
const m2 = HashMap.mergeAll('none', m, [[2, true]], HashMap.of([3, 15]))
// type of m2: HashMap<number, [string, boolean | string, number | string]>
console.log(m2.toArray())
// => [[1, ['a', 'none', 'none']], [2, ['b', true, 'none']], [3, ['none', 'none', 15]]]
Overrides
mergeAllWith
Returns a Map containing all keys from this map and all the given sources
key-value stream sources, and as values the result of applying the given mergeFun
to the key and all the corresponding values for each key. If a source doesn't have a key, the given tuple will be filled with the given fillValue
.
mergeAllWith
sources
key-value stream sources, and as values the result of applying the given mergeFun
to the key and all the corresponding values for each key. If a source doesn't have a key, the given tuple will be filled with the given fillValue
.Definitions
mergeAllWith<I extends readonly [unknown, unknown, ...unknown[]], K extends UK>(...sources: {
[KT in keyof I]:
StreamSource.NonEmpty
<readonly [K, I[KT]]>;
} & unknown[]): <O, R>(fillValue: O, mergeFun: (key: K, ...values: {
[KT in keyof I]: I[KT]
|
O;
}) => R) =>
WithKeyValue
<Tp, K, R>['nonEmpty'];
mergeAllWith<I extends readonly [unknown, unknown, ...unknown[]], K extends UK>(...sources: {
[KT in keyof I]:
StreamSource
<readonly [K, I[KT]]>;
} & unknown[]): <O, R>(fillValue: O, mergeFun: (key: K, ...values: {
[KT in keyof I]: I[KT]
|
O;
}) => R) =>
WithKeyValue
<Tp, K, R>['normal'];
Type parameters
Name | Constraints | Description |
---|---|---|
I | readonly [unknown, unknown, ...unknown[]] | the array of input source value types |
K | UK | the common key type |
Parameters
Name | Type | Description |
---|---|---|
sources | { [KT in keyof I]: StreamSource.NonEmpty <readonly [K, I[KT]]>; } & unknown[] | a non-empty set of StreamSouces containing tuples of keys and values |
const m = HashMap.of([1, 'a'], [2, 'b'])
const m2 = HashMap.mergeAllWith(
m
[[2, 'c']],
HashMap.of([3, 'd'])
)(
'q',
(key, v1, v2, v3) => `${key}${v1}${v2}${v3}`
)
// type of m2: HashMap<number, string>
console.log(m2.toArray())
// => [[1, '1aqq'], [2, '2bcq'], [3, '3qqd']]
Overrides
mergeWith
Returns a Map containing the common keys from this map and all the given sources
key-value stream sources, and as values the result of applying given mergeFun
to the key and values of all the corresponding values for each common key. If a source doesn't have a key, the key will be skipped.
mergeWith
sources
key-value stream sources, and as values the result of applying given mergeFun
to the key and values of all the corresponding values for each common key. If a source doesn't have a key, the key will be skipped.Definitions
mergeWith<I extends readonly [unknown, unknown, ...unknown[]], K extends UK>(...sources: {
[KT in keyof I]:
StreamSource.NonEmpty
<readonly [K, I[KT]]>;
} & unknown[]): <R>(mergeFun: (key: K, ...values: I) => R) =>
WithKeyValue
<Tp, K, R>['nonEmpty'];
mergeWith<I extends readonly [unknown, unknown, ...unknown[]], K extends UK>(...sources: {
[KT in keyof I]:
StreamSource
<readonly [K, I[KT]]>;
} & unknown[]): <R>(mergeFun: (key: K, ...values: I) => R) =>
WithKeyValue
<Tp, K, R>['normal'];
Type parameters
Name | Constraints | Description |
---|---|---|
I | readonly [unknown, unknown, ...unknown[]] | the array of input source value types |
K | UK | the common key type |
Parameters
Name | Type | Description |
---|---|---|
sources | { [KT in keyof I]: StreamSource.NonEmpty <readonly [K, I[KT]]>; } & unknown[] | a non-empty set of StreamSouces containing tuples of keys and values |
const m = HashMap.of([1, 'a'], [2, 'b'])
const m2 = HashMap.mergeWith(
m,
[[2, true]],
HashMap.of([2, 15])
)(
(key, v1, v2) => `${key}${v1}${v2}`,
)
// type of m2: HashMap<number, string>
console.log(m2.toArray())
// => [[2, '2true15']]
Overrides
of
Returns an immutable map of this collection type and context, containing the given entries
.
of
entries
.Definition
of<K extends UK, V>(...entries:
ArrayNonEmpty
<readonly [K, V]>):
WithKeyValue
<Tp, K, V>['nonEmpty'];
Type parameters
Name | Constraints | Description |
---|---|---|
K | UK | |
V |
Parameters
Name | Type | Description |
---|---|---|
entries | ArrayNonEmpty <readonly [K, V]> | a non-empty array of key-value entries |
HashMap.of([1, 'a'], [2, 'b']) // => HashMap.NonEmpty<number, string>
Overrides
reducer
Returns a Reducer
that adds received tuples to an RMap and returns the RMap as a result. When a source
is given, the reducer will first create an RMap from the source, and then add tuples to it.
reducer
Reducer
that adds received tuples to an RMap and returns the RMap as a result. When a source
is given, the reducer will first create an RMap from the source, and then add tuples to it.Definition
reducer<K extends UK, V>(source?:
StreamSource
<readonly [K, V]>): Reducer<readonly [K, V],
WithKeyValue
<Tp, K, V>['normal']>;
Type parameters
Name | Constraints | Description |
---|---|---|
K | UK | |
V |
Parameters
Name | Type | Description |
---|---|---|
source | StreamSource <readonly [K, V]> | (optional) an initial source of tuples to add to |
const someSource = HashMap.of([1, 'a'], [2, 'b']);
const result = Stream.of([1, 'c'], [3, 'a']).reduce(HashMap.reducer(someSource))
result.toArray() // => [[1, 'c'], [2, 'b'], [3, 'a']]
uses a builder under the hood. If the given source
is an RMap in the same context, it will directly call .toBuilder()
.