Skip to main content
Module

x/rimbu/collection-types/map-custom/index.ts>VariantMapBase

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
namespace VariantMapBase
import { VariantMapBase } from "https://deno.land/x/rimbu@0.13.1/collection-types/map-custom/index.ts";

Interfaces

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

interface VariantMapBase
implements FastIterable<readonly [K, V]>
import { type VariantMapBase } from "https://deno.land/x/rimbu@0.13.1/collection-types/map-custom/index.ts";

Properties

readonly
isEmpty: boolean

Returns true if the collection is empty.

readonly
size: number

Returns the number of entries

Methods

nonEmpty(): this is WithKeyValue<Tp, K, V>["nonEmpty"]

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(): WithKeyValue<Tp, K, V>["nonEmpty"]

Returns the collection as a .NonEmpty type

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.

get<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.

get<UK, O>(key: RelatedTo<K, UK>, otherwise: OptLazy<O>): V | O
hasKey<UK = K>(key: RelatedTo<K, UK>): boolean

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

removeKey<UK = K>(key: RelatedTo<K, UK>): WithKeyValue<Tp, K, V>["normal"]

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

removeKeys<UK = K>(keys: StreamSource<RelatedTo<K, UK>>): WithKeyValue<Tp, K, V>["normal"]

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

removeKeyAndGet<UK = K>(key: RelatedTo<K, UK>): [WithKeyValue<Tp, K, V>["normal"], 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.

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.

mapValues<V2>(mapFun: (value: V, key: K) => V2): (Tp & KeyValue<K, V2>)["normal"]

Returns a collection with the same keys, but where the given mapFun function is applied to each entry value.

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

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

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])[]>

Returns a JSON representation of this collection.