Skip to main content

interface 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 *

Extends: Streamable.NonEmpty<T>, BiMap<K,V>

Implemented by: BiMapNonEmptyImpl<K,V>

Type parameters

NameDescription
Kthe key type
Vthe value type

Properties

context

Returns the context associated to this collection instance.

Definition

readonly context: BiMap.Context<K, V>;

Overrides

BiMap.context

isEmpty

Returns false since this collection is known to be non-empty.

Definition

readonly isEmpty: false;

example
BiMap.of([1, 1], [2, 2]).isEmpty   // => false

Overrides

BiMap.isEmpty

keyValueMap

Returns the non-empty Map representation of the key to value mapping.

Definition

readonly keyValueMap: RMap.NonEmpty<K, V>;

example
BiMap.of([1, 10], [2, 20]).keyValueMap.toArray()
// => [[1, 10], [2, 20]]

Overrides

BiMap.keyValueMap

size

Returns the number of entries

Definition

readonly size: number;

example
BiMap.of([1, 1], [2, 2]).size       // => 2

Overrides

BiMap.size

valueKeyMap

Returns the non-empty Map representation of the key to value mapping.

Definition

readonly valueKeyMap: RMap.NonEmpty<V, K>;

example
BiMap.of([1, 10], [2, 20]).valueKeyMap.toArray()
// => [[10, 1], [20, 2]]

Overrides

BiMap.valueKeyMap

Methods

[Symbol.iterator]

Returns a FastIterator instance used to iterate over the values of this Iterable.

Definition

[Symbol.iterator](): FastIterator<T>;

Overrides

FastIterable.[Symbol.iterator]

addEntries

Returns the collection with the entries from the given StreamSource entries added.

Definition

addEntries(entries: StreamSource<readonly [K, V]>): BiMap.NonEmpty<K, V>;

Parameters

NameTypeDescription
entriesStreamSource<readonly [K, V]>a StreamSource containing tuples with a key and value
example
BiMap.of([1, 1]).addEntries([[2, 2], [1, 3]]).toArray()
// => [[1, 2]]

Overrides

BiMap.addEntries

addEntry

Returns the collection with given entry added.

Definition

addEntry(entry: readonly [K, V]): BiMap.NonEmpty<K, V>;

Parameters

NameTypeDescription
entryreadonly [K, V]a tuple containing a key and value
example
BiMap.of([1, 1], [2, 2]).addEntry([1, 2]).toArray()
// => [[1, 2]]

Overrides

BiMap.addEntry

asNormal

Returns this collection typed as a 'possibly empty' collection.

Definition

asNormal(): BiMap<K, V>;

example
BiMap.of([1, 1], [2, 2]).asNormal();  // type: BiMap<number, number>

assumeNonEmpty

Returns a self reference since this collection is known to be non-empty.

Definition

assumeNonEmpty(): this;

example
const m = BiMap.of([1, 1], [2, 2]);
m === m.assumeNonEmpty() // => true

Overrides

BiMap.assumeNonEmpty

filter

Returns a collection containing only those entries that satisfy given pred predicate.

Definition

filter(pred: (entry: readonly [K, V], index: number, halt: () => void) => boolean, options?: {
    negate?: boolean;
  }): BiMap<K, V>;

Parameters

NameTypeDescription
pred(entry: readonly [K, V], index: number, halt: () => void) => booleana predicate function receiving:
- entry: the next entry
- index: the entry index
- halt: a function that, when called, ensures no next elements are passed
options{
    negate?: boolean;
  }
(optional) an object containing the following properties:
- negate: (default: false) when true will negate the given predicate
example
BiMap.of([1, 'a'], [2, 'b'], [3, 'c']).filter(entry => entry[0] === 2 || entry[1] === 'c').toArray()
// => [[2, 'b'], [3, 'c']]

Overrides

BiMap.filter

forEach

Performs given function f for each entry of the collection, using given state as initial traversal state.

Definition

forEach(f: (entry: readonly [K, V], index: number, halt: () => void) => void, options?: {
    state?: TraverseState;
  }): void;

Parameters

NameTypeDescription
f(entry: readonly [K, V], index: number, halt: () => void) => voidthe function to perform for each entry, receiving:
- entry: the next tuple of a key and value
- 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
example
BiMap.of([1, 'a'], [2, 'b'], [3, 'c']).forEach((entry, i, halt) => {
console.log([entry[1], entry[0]]);
if (i >= 1) halt();
})
// => logs ['a', 1] ['b', 2]
note

O(N)

Overrides

BiMap.forEach

getKey

Returns the key associated with the given value, or given otherwise value if the key 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

NameDefaultDescription
UVV

Parameters

NameTypeDescription
valueRelatedTo<V, UV>thevalue to look for
example
const m = BiMap.of([1, 'a'], [2, 'b'])
m.getKey('b') // => 2
m.getKey('z') // => undefined
m.getKey('b', 'none') // => 2
m.getKey('z', 'none') // => 'none'

Overrides

BiMap.getKey

getValue

Returns the value associated with the given key, 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

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the key to look for
example
const m = BiMap.of([1, 'a'], [2, 'b'])
m.getValue(2) // => 'b'
m.getValue(3) // => undefined
m.getValue(2, 'none') // => 'b'
m.getValue(3, 'none') // => 'none'

Overrides

BiMap.getValue

hasKey

Returns true if the given key is present in the collection.

Definition

hasKey<UK = K>(key: RelatedTo<K, UK>): boolean;

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the key to look for
example
const m = BiMap.of([1, 'a'], [2, 'b'])
m.hasKey(2) // => true
m.hasKey(3) // => false

Overrides

BiMap.hasKey

hasValue

Returns true if the given value is present in the collection.

Definition

hasValue<UV = V>(key: RelatedTo<V, UV>): boolean;

Type parameters

NameDefaultDescription
UVV

Parameters

NameTypeDescription
keyRelatedTo<V, UV>
example
const m = BiMap.of([1, 'a'], [2, 'b'])
m.hasKey('a') // => true
m.hasKey('z') // => false

Overrides

BiMap.hasValue

nonEmpty

Returns true since this collection is known to be non-empty

Definition

nonEmpty(): this is BiMap.NonEmpty<K, V>;

example
BiMap.of([1, 1], [2, 2]).nonEmpty()   // => true

Overrides

BiMap.nonEmpty

removeKey

Returns the collection where the entry associated with given key is removed if it was part of the collection.

Definition

removeKey<UK = K>(key: RelatedTo<K, UK>): BiMap<K, V>;

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the key of the entry to remove
example
const m = BiMap.of([1, 1], [2, 2])
m.removeKey(2).toArray() // => [[1, 1]]
m.removeKey(3) === m // true
note

guarantees same object reference if the key is not present

Overrides

BiMap.removeKey

removeKeyAndGet

Returns a tuple containing the collection of which the entry associated with given key is removed, and the value that is associated with that key. If the key is not present, it will return undefined instead.

Definition

removeKeyAndGet<UK = K>(key: RelatedTo<K, UK>): [BiMap<K, V>, V] | undefined;

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the key of the entry to remove
example
const m = BiMap.of([1, 1], [2, 2])
const result = m.removeKeyAndGet(2)
if (result !== undefined) console.log([result[0].toString(), result[1]]) // => logs [BiMap(1 <=> 1), 2]
console.log(m.removeKeyAndGet(3)) // => logs undefined

Overrides

BiMap.removeKeyAndGet

removeKeys

Returns the collection where the entries associated with each key in given keys are removed if they were present.

Definition

removeKeys<UK = K>(keys: StreamSource<RelatedTo<K, UK>>): BiMap<K, V>;

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keysStreamSource<RelatedTo<K, UK>>a StreamSource of keys to remove
example
const m = BiMap.of([1, 1], [2, 2])
m.removeKeys([1, 3]).toArray() // => [[2, 2]]
m.removeKeys([1, 3, 2]).toArray() // => []
m.removeKeys([3, 4, 5]) === m // => true
note

guarantees same object reference if none of the keys are present

Overrides

BiMap.removeKeys

removeValue

Returns the collection where the entry associated with given value is removed if it was part of the collection.

Definition

removeValue<UV = V>(value: RelatedTo<V, UV>): BiMap<K, V>;

Type parameters

NameDefaultDescription
UVV

Parameters

NameTypeDescription
valueRelatedTo<V, UV>the value of the entry to remove
example
const m = BiMap.of([1, 1], [2, 2])
m.removeValue(2).toArray() // => [[1, 1]]
m.removeValue(3) === m // true
note

guarantees same object reference if the key is not present

Overrides

BiMap.removeValue

removeValueAndGet

Returns a tuple containing the collection of which the entry associated with given value is removed, and the key that is associated with that value. If the value is not present, it will return undefined instead.

Definition

removeValueAndGet<UV = V>(value: RelatedTo<V, UV>): [BiMap<K, V>, K] | undefined;

Type parameters

NameDefaultDescription
UVV

Parameters

NameTypeDescription
valueRelatedTo<V, UV>the value of the entry to remove
example
const m = BiMap.of([1, 1], [2, 2])
const result = m.removeValueAndGet(2)
if (result !== undefined) console.log([result[0].toString(), result[1]]) // => logs [BiMap(1 <=> 1), 2]
console.log(m.removeValueAndGet(3)) // => logs undefined

Overrides

BiMap.removeValueAndGet

removeValues

Returns the collection where the entries associated with each value in given values are removed if they were present.

Definition

removeValues<UV = V>(value: StreamSource<RelatedTo<V, UV>>): BiMap<K, V>;

Type parameters

NameDefaultDescription
UVV

Parameters

NameTypeDescription
valueStreamSource<RelatedTo<V, UV>>
example
const m = BiMap.of([1, 1], [2, 2])
m.removeValues([1, 3]).toArray() // => [[2, 2]]
m.removeValues([1, 3, 2]).toArray() // => []
m.removeValues([3, 4, 5]) === m // => true
note

guarantees same object reference if none of the keys are present

Overrides

BiMap.removeValues

set

Returns the collection with the given key associated to the given value.

Definition

set(key: K, value: V): BiMap.NonEmpty<K, V>;

Parameters

NameTypeDescription
keyKthe entry key to add
valueVthe entry value to add
example
BiMap.of([1, 1], [2, 2]).set(1, 2).toArray()
// => [[1, 2]]
note

if the key and/or value are already associated, the previous value will be 'replaced'

Overrides

BiMap.set

stream

Returns a non-empty Stream containing all entries of this collection as tuples of key and value.

Definition

stream(): Stream.NonEmpty<readonly [K, V]>;

example
BiMap.of([1, 1], [2, 2]).stream().toArray()  // => [[1, 1], [2, 2]]

Overrides

NonEmpty.stream, BiMap.stream

streamKeys

Returns a non-empty Stream containing all keys of this collection.

Definition

streamKeys(): Stream.NonEmpty<K>;

example
BiMap.of([[1, 'a'], [2, 'b']]).streamKeys().toArray()   // => [1, 2]

Overrides

BiMap.streamKeys

streamValues

Returns a non-empty Stream containing all values of this collection.

Definition

streamValues(): Stream.NonEmpty<V>;

example
BiMap.of([[1, 'a'], [2, 'b']]).streamValues().toArray()   // => ['a', 'b']

Overrides

BiMap.streamValues

toArray

Returns a non-empty array containing all entries in this collection.

Definition

toArray(): ArrayNonEmpty<readonly [K, V]>;

example
BiMap.of([1, 'a'], [2, 'b']).toArray()   // => [[1, 'a'], [2, 'b']]
note

O(log(N)) @note it is safe to mutate the returned array, however, the array elements are not copied, thus should be treated as read-only

Overrides

BiMap.toArray

toBuilder

Returns a builder object containing the entries of this collection.

Definition

toBuilder(): BiMap.Builder<K, V>;

example
const builder: BiMap.Builder<number, string> = BiMap.of([1, 'a'], [2, 'b']).toBuilder()

Overrides

BiMap.toBuilder

toJSON

Returns a JSON representation of this collection.

Definition

toJSON(): ToJSON<(readonly [K, V])[], this['context']['typeTag']>;

example
BiMap.of([1, 'a'], [2, 'b']).toJSON()   // => { dataType: 'BiMap', value: [[1, 'a'], [2, 'b']] }

Overrides

BiMap.toJSON

toString

Returns a string representation of this collection.

Definition

toString(): string;

example
BiMap.of([1, 'a'], [2, 'b']).toString()   // => BiMap(1 <=> 'a', 2 <=> 'b')

Overrides

BiMap.toString

updateKeyAtValue

Returns the collection where the key associated with given value is updated with the given update value or update function.

Definition

updateKeyAtValue<UV = V>(keyUpdate: Update<K>, value: RelatedTo<V, UV>): BiMap.NonEmpty<K, V>;

Type parameters

NameDefaultDescription
UVV

Parameters

NameTypeDescription
keyUpdateUpdate<K>a new value or function taking the current key and returning a new key
valueRelatedTo<V, UV>the value of the entry to update
example
const m = BiMap.of([1, 1], [2, 2])
m.updateKeyAtValue(3, 3).toArray()
// => [[1, 1], [2, 2]]
m.updateKeyAtValue(10, 2).toArray()
// => [[1, 1], [10, 2]]
m.updateKeyAtValue((v) => v + 1, 1)
// => [[2, 1]]

Overrides

BiMap.updateKeyAtValue

updateValueAtKey

Returns the collection where the value associated with given key is updated with the given update value or update function.

Definition

updateValueAtKey<UK = K>(key: RelatedTo<K, UK>, valueUpdate: Update<V>): BiMap.NonEmpty<K, V>;

Type parameters

NameDefaultDescription
UKK

Parameters

NameTypeDescription
keyRelatedTo<K, UK>the key of the entry to update
valueUpdateUpdate<V>a new value or function taking the current value and returning a new value
example
const m = BiMap.of([1, 1], [2, 2])
m.updateValueAt(3, 3).toArray()
// => [[1, 1], [2, 2]]
m.updateValueAt(2, 10).toArray()
// => [[1, 1], [2, 10]]
m.updateValueAt(1, v => v + 1)
// => [[1, 2]]

Overrides

BiMap.updateValueAtKey