Skip to main content

namespace OrderedHashMap

A type-invariant immutable Ordered HashMap of key type K, and value type V. In the Map, each key has exactly one value, and the Map cannot contain duplicate keys. See the Map documentation and the OrderedHashMap API documentation

Companion interface: OrderedHashMap<K,V>

Interfaces​

NameDescription
OrderedHashMap.Builder<K,V>A mutable OrderedHashMap builder used to efficiently create new immutable instances. See the Map documentation and the OrderedHashMap.Builder API documentation
OrderedHashMap.Context<UK>A context instance for an OrderedHashMap that acts as a factory for every instance of this type of collection.
OrderedHashMap.NonEmpty<K,V>A non-empty type-invariant immutable Ordered HashMap of key type K, and value type V. In the Map, each key has exactly one value, and the Map cannot contain duplicate keys. See the Map documentation and the OrderedHashMap API documentation
OrderedHashMap.TypesUtility interface that provides higher-kinded types for this collection.

Static Methods​

builder​

Returns an empty builder instance for this type of collection and context.

Definition​

builder<K extends UK, V>(): WithKeyValue<Tp, K, V>['builder'];

Type parameters​

NameConstraintsDescription
KUK
V
example
HashMap.builder<number, string>()    // => HashMap.Builder<number, string>

Overrides​

Factory.builder

createContext​

Returns a new OrderedHashMap context instance based on the given options.

Definition​

createContext<UK>(options?: {
    listContext?: List.Context;
    mapContext?: HashMap.Context<UK>;
  }): OrderedHashMap.Context<UK>;

Type parameters​

NameDescription
UKthe upper key type for which the context can create instances

Parameters​

NameTypeDescription
options{
    listContext?: List.Context;
    mapContext?: HashMap.Context<UK>;
  }
(optional) an object containing the following properties:
- listContext: (optional) the list context to use for key ordering
- mapContext: (optional) the map context to use for key value mapping

defaultContext​

Returns the default context for OrderedHashMaps.

Definition​

defaultContext<UK>(): OrderedHashMap.Context<UK>;

Type parameters​

NameDescription
UKthe upper key type for which the context can create instances

empty​

Returns the (singleton) empty instance of this type and context with given key and value types.

Definition​

empty<K extends UK, V>(): WithKeyValue<Tp, K, V>['normal'];

Type parameters​

NameConstraintsDescription
KUK
V
example
HashMap.empty<number, string>()    // => HashMap<number, string>
HashMap.empty<string, boolean>() // => HashMap<string, boolean>

Overrides​

Factory.empty

from​

Returns an immutable map of this type and context, containing the entries in the given 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​

NameConstraintsDescription
KUK
V

Parameters​

NameTypeDescription
sourcesArrayNonEmpty<StreamSource.NonEmpty<readonly [K, V]>>an array of StreamSource instances containing key-value entries
example
HashMap.from([[1, 'a'], [2, 'b']])    // => HashMap.NonEmpty<number, string>

Overrides​

Factory.from

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.

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​

NameConstraintsDescription
KUKthe common key type
Ireadonly [unknown, unknown, ...unknown[]]the array of input source value types

Parameters​

NameTypeDescription
sources{
      [KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
    } & unknown[]
a non-empty set of StreamSources containing tuples of keys and values
example
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​

Factory.merge

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.

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​

NameConstraintsDescription
Othe type of the fill value
Ireadonly [unknown, unknown, ...unknown[]]the array of input source value types
KUKthe common key type

Parameters​

NameTypeDescription
fillValueOthe 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 StreamSources containing tuples of keys and values
example
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​

Factory.mergeAll

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.

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​

NameConstraintsDescription
Ireadonly [unknown, unknown, ...unknown[]]the array of input source value types
KUKthe common key type

Parameters​

NameTypeDescription
sources{
      [KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
    } & unknown[]
a non-empty set of StreamSources containing tuples of keys and values
example
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​

Factory.mergeAllWith

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.

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​

NameConstraintsDescription
Ireadonly [unknown, unknown, ...unknown[]]the array of input source value types
KUKthe common key type

Parameters​

NameTypeDescription
sources{
      [KT in keyof I]: StreamSource.NonEmpty<readonly [K, I[KT]]>;
    } & unknown[]
a non-empty set of StreamSources containing tuples of keys and values
example
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​

Factory.mergeWith

of​

Returns an immutable map of this collection type and context, containing the given entries.

Definition​

of<K extends UK, V>(...entries: ArrayNonEmpty<readonly [K, V]>): WithKeyValue<Tp, K, V>['nonEmpty'];

Type parameters​

NameConstraintsDescription
KUK
V

Parameters​

NameTypeDescription
entriesArrayNonEmpty<readonly [K, V]>a non-empty array of key-value entries
example
HashMap.of([1, 'a'], [2, 'b'])    // => HashMap.NonEmpty<number, string>

Overrides​

Factory.of

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.

Definition​

reducer<K extends UK, V>(source?: StreamSource<readonly [K, V]>): Reducer<readonly [K, V], WithKeyValue<Tp, K, V>['normal']>;

Type parameters​

NameConstraintsDescription
KUK
V

Parameters​

NameTypeDescription
sourceStreamSource<readonly [K, V]>(optional) an initial source of tuples to add to
example
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']]
note

uses a builder under the hood. If the given source is an RMap in the same context, it will directly call .toBuilder().

Overrides​

Factory.reducer