interface 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
Type parameters
| Name | Description |
|---|---|
| K | the key type |
| V | the value type |
Properties
isEmpty
Returns true if there are no entries in the builder.
isEmptyDefinition
readonly isEmpty: boolean;
BiMap.of([[1, 'a'], [2, 'b']]).toBuilder().isEmpty
// => false
size
Returns the amount of entries in the builder.
sizeMethods
addEntries
Adds given entries to the builder.
addEntriesentries to the builder.Definition
addEntries(entries: StreamSource<readonly [K, V]>): boolean;
Parameters
| Name | Type | Description |
|---|---|---|
entries | StreamSource<readonly [K, V]> |
const m = BiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.addEntries([1, 'a'], [3, 'c']]) // => true
m.addEntries([]) // => false
addEntry
Adds the given entry to the builder, where the entry key is associated with the entry value.
addEntryentry to the builder, where the entry key is associated with the entry value.build
Returns an immutable collection instance containing the entries in this builder.
buildforEach
Performs given function f for each entry of the builder.
forEachf for each entry of the builder.Definition
forEach(f: (entry: readonly [K, V], index: number, halt: () => void) => void, options?: {
state?: TraverseState;
}): void;
Parameters
| Name | Type | Description |
|---|---|---|
f | (entry: readonly [K, V], index: number, halt: () => void) => void | the function to perform for each element, receiving: - entry: the next key-value entry- index: the index of the element- halt: a function that, if called, ensures that no new elements are passed |
options | {state?: TraverseState;} | (optional) an object containing the following properties: - state: (optional) the traverse state |
RibuError.ModifiedBuilderWhileLoopingOverItError if the builder is modified while looping over it
BiMap.of([1, 'a'], [2, 'b'], [3, 'c']).toBuilder().forEach((entry, i, halt) => {
console.log([entry[1], entry[0]]);
if (i >= 1) halt();
})
// => logs ['a', 1] ['b', 2]
O(N)
getKey
Returns the key associated with the given value, or given otherwise value if the value is not in the collection.
getKeyvalue, or given otherwise value if the value is not in the collection.Definitions
getKey<UV = V>(value: RelatedTo<V, UV>): K | undefined;
getKey<UV, O>(value: RelatedTo<V, UV>, otherwise: OptLazy<O>): K | O;
Type parameters
| Name | Default | Description |
|---|---|---|
| UV | V |
Parameters
| Name | Type | Description |
|---|---|---|
value | RelatedTo<V, UV> | the value to look for |
const m = BiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.getKey('b') // => 2
m.getKey('z') // => undefined
m.getKey('b', 'none') // => 2
m.getKey('z', 'none') // => 'none'
getValue
Returns the value associated with the given key, or given otherwise value if the key is not in the collection.
getValuekey, or given otherwise value if the key is not in the collection.Definitions
getValue<UK = K>(key: RelatedTo<K, UK>): V | undefined;
getValue<UK, O>(key: RelatedTo<K, UK>, otherwise: OptLazy<O>): V | O;
Type parameters
| Name | Default | Description |
|---|---|---|
| UK | K |
Parameters
| Name | Type | Description |
|---|---|---|
key | RelatedTo<K, UK> | the key to look for |
const m = BiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.getValue(2) // => 'b'
m.getValue(3) // => undefined
m.getValue(2, 'none') // => 'b'
m.getValue(3, 'none') // => 'none'
hasKey
Returns true if the given key is present in the builder.
hasKeykey is present in the builder.hasValue
Returns true if the given value is present in the builder.
hasValuevalue is present in the builder.removeKey
Removes the entries related to given key from the builder.
removeKeykey from the builder.Definitions
removeKey<UK = K>(key: RelatedTo<K, UK>): V | undefined;
removeKey<UK, O>(key: RelatedTo<K, UK>, otherwise: OptLazy<O>): V | O;
Type parameters
| Name | Default | Description |
|---|---|---|
| UK | K |
Parameters
| Name | Type | Description |
|---|---|---|
key | RelatedTo<K, UK> | the key to remove |
const m = BiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.removeKey(2) // => 'b'
m.removeKey(3) // => undefined
m.removeKey(3, 'c') // => 'c'
removeKeys
Removes the entries related to the given keys StreamSource from the builder.
removeKeyskeys StreamSource from the builder.Definition
removeKeys<UK = K>(keys: StreamSource<RelatedTo<K, UK>>): boolean;
Type parameters
| Name | Default | Description |
|---|---|---|
| UK | K |
Parameters
| Name | Type | Description |
|---|---|---|
keys | StreamSource<RelatedTo<K, UK>> |
const m = BiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.removeKeys([3, 4, 5]) // => false
m.removeKeys([1, 10]) // => true
removeValue
Removes the entries related to given value from the builder.
removeValuevalue from the builder.Definitions
removeValue<UV = V>(value: RelatedTo<V, UV>): K | undefined;
removeValue<UV, O>(value: RelatedTo<V, UV>, otherwise: OptLazy<O>): K | O;
Type parameters
| Name | Default | Description |
|---|---|---|
| UV | V |
Parameters
| Name | Type | Description |
|---|---|---|
value | RelatedTo<V, UV> | the value to remove |
const m = BiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.removeValue('b') // => 2
m.removeValue('c') // => undefined
m.removeValue('c', 0) // => 0
removeValues
Removes the entries related to the given values StreamSource from the builder.
removeValuesvalues StreamSource from the builder.Definition
removeValues<UV = V>(values: StreamSource<RelatedTo<V, UV>>): boolean;
Type parameters
| Name | Default | Description |
|---|---|---|
| UV | V |
Parameters
| Name | Type | Description |
|---|---|---|
values | StreamSource<RelatedTo<V, UV>> |
const m = BiMap.of([1, 'a'], [2, 'b']).toBuilder()
m.removeValues(['c', 'd', 'e']) // => false
m.removeValues(['a', 'e']) // => true