namespace BiMap
A type-invariant immutable bi-directional Map where keys and values have a one-to-one mapping. See the BiMap documentation and the BiMap API documentation
Companion interface: BiMap<K,V>
Interfaces
| Name | Description |
|---|---|
BiMap.Builder<K,V> | A mutable BiMap builder used to efficiently create new immutable instances. See the BiMap documentation and the BiMap.Builder API documentation |
BiMap.Context<UK,UV,Tp> | The BiMap's Context instance that serves as a factory for all related immutable instances and builders. |
BiMap.NonEmpty<K,V> | A non-empty type-invariant immutable bi-directional Map where keys and values have a one-to-one mapping. See the BiMap documentation and the BiMap API documentation * |
BiMap.Types | Utility interface that provides higher-kinded types for this collection. |
Static Methods
builder
Returns an empty BiMap builder instance.
builderBiMap builder instance.createContext
Returns a new BiMap context instance based on the given options.
createContextoptions.Definition
createContext<UK, UV>(options?: {
keyValueContext?: RMap.Context<UK>;
valueKeyContext?: RMap.Context<UV>;
}): BiMap.Context<UK, UV>;
Type parameters
| Name | Description |
|---|---|
| UK | the upper key type for which the context can create instances |
| UV | the upper value type for which the context can create instances |
Parameters
| Name | Type | Description |
|---|---|---|
options | {keyValueContext?: RMap.Context<UK>;valueKeyContext?: RMap.Context<UV>;} | (optional) an object containing the following properties: - keyValueContext: (optional) the map context to use for key value mappings - valueKeyContext: (optional) the map context to use for value key mappings |
defaultContext
Returns the default context for BiMaps.
defaultContextempty
Returns the (singleton) empty instance of this type and context with given key and value types.
emptyfrom
Returns an immutable BiMap, containing the entries in the given sources StreamSource instances.
fromsources StreamSource instances.Definitions
from<K extends UK, V extends UV>(...sources: ArrayNonEmpty<StreamSource<readonly [K, V]>>): BiMap.NonEmpty<K, V>;
from<K extends UK, V extends UV>(...sources: ArrayNonEmpty<StreamSource.NonEmpty<readonly [K, V]>>): BiMap<K, V>;
Type parameters
| Name | Constraints | Description |
|---|---|---|
| K | UK | |
| V | UV |
Parameters
| Name | Type | Description |
|---|---|---|
sources | ArrayNonEmpty<StreamSource<readonly [K, V]>> | an array of StreamSource instances contaning key-value entries |
BiMap.from([[1, 'a'], [2, 'b']]) // => BiMap.NonEmpty<number, string>
Overrides
of
Returns an immutable BiMap, containing the given entries.
ofBiMap, containing the given entries.Definition
of<K extends UK, V extends UV>(...entries: ArrayNonEmpty<readonly [K, V]>): BiMap.NonEmpty<K, V>;
Type parameters
| Name | Constraints | Description |
|---|---|---|
| K | UK | |
| V | UV |
Parameters
| Name | Type | Description |
|---|---|---|
entries | ArrayNonEmpty<readonly [K, V]> | a non-empty array of key-value entries |
BiMap.of([1, 'a'], [2, 'b']) // => BiMap.NonEmpty<number, string>
Overrides
reducer
Returns a Reducer that adds received tuples to a BiMap and returns the BiMap as a result. When a source is given, the reducer will first create a BiMap from the source, and then add tuples to it.
reducerReducer that adds received tuples to a BiMap and returns the BiMap as a result. When a source is given, the reducer will first create a BiMap from the source, and then add tuples to it.Definition
reducer<K extends UK, V extends UV>(source?: StreamSource<readonly [K, V]>): Reducer<readonly [K, V], BiMap<K, V>>;
Type parameters
| Name | Constraints | Description |
|---|---|---|
| K | UK | |
| V | UV |
Parameters
| Name | Type | Description |
|---|---|---|
source | StreamSource<readonly [K, V]> | (optional) an initial source of tuples to add to |
const someSource = BiMap.of([1, 'a'], [2, 'b']);
const result = Stream.of([1, 'c'], [3, 'a']).reduce(BiMap.reducer(someSource))
result.toArray() // => [[1, 'c'], [2, 'b'], [3, 'a']]
uses a builder under the hood. If the given source is a BiMap in the same context, it will directly call .toBuilder().