Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/bimap/main/interface.ts>BiMap

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
namespace BiMap
import { BiMap } from "https://deno.land/x/rimbu@0.13.0/bimap/main/interface.ts";

Interfaces

A mutable BiMap builder used to efficiently create new immutable instances. See the BiMap documentation and the BiMap.Builder API documentation

The BiMap's Context instance that serves as a factory for all related immutable instances and builders.

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 * @typeparam K - the key type

Utility interface that provides higher-kinded types for this collection.

interface BiMap
implements FastIterable<readonly [K, V]>
import { type BiMap } from "https://deno.land/x/rimbu@0.13.0/bimap/main/interface.ts";

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

Examples

Example 1

const b1 = BiMap.empty<number, string>()
const b2 = BiMap.of([1, 'a'], [2, 'b'])

Properties

readonly
context: BiMap.Context<K, V>

Returns the context associated to this collection instance.

readonly
isEmpty: boolean

Returns true if the collection is empty.

readonly
size: number

Returns the number of entries

readonly
keyValueMap: RMap<K, V>

Returns the Map representation of the key to value mapping.

readonly
valueKeyMap: RMap<V, K>

Returns the Map representation of the key to value mapping.

Methods

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

Returns true if there is at least one entry in the collection, and instructs the compiler to treat the collection as a .NonEmpty type.

assumeNonEmpty(): BiMap.NonEmpty<K, V>

Returns the collection as a .NonEmpty type

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

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

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

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

getValue<UK = K>(key: RelatedTo<K, UK>): V | undefined

Returns the value associated with the given key, or given otherwise value if the key is not in the collection.

getValue<UK, O>(key: RelatedTo<K, UK>, otherwise: OptLazy<O>): V | O
getKey<UV = V>(value: RelatedTo<V, UV>): K | undefined

Returns the key associated with the given value, or given otherwise value if the key is not in the collection.

getKey<UV, O>(value: RelatedTo<V, UV>, otherwise: OptLazy<O>): K | O
set(key: K, value: V): BiMap.NonEmpty<K, V>

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

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

Returns the collection with given entry added.

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

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

addEntries(entries: StreamSource<readonly [K, V]>): BiMap<K, V>
removeKey<UK = K>(key: RelatedTo<K, UK>): BiMap<K, V>

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

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

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.

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

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

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

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

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

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.

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

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

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

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

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

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

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

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

streamKeys(): Stream<K>

Returns a Stream containing all keys of this collection.

streamValues(): Stream<V>

Returns a Stream containing all values of this collection.

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

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

filter(pred: (
entry: readonly [K, V],
index: number,
halt: () => void,
) => boolean
): BiMap<K, V>

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

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

Returns a builder object containing the entries of this collection.

toArray(): (readonly [K, V])[]

Returns an array containing all entries in this collection.

toString(): string

Returns a string representation of this collection.

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

Returns a JSON representation of this collection.

variable BiMap
import { BiMap } from "https://deno.land/x/rimbu@0.13.0/bimap/main/interface.ts";