UNPKG

@thi.ng/associative

Version:

ES Map/Set-compatible implementations with customizable equality semantics & supporting operations

47 lines 1.99 kB
import type { Fn3, ICopy, IEmpty, IEquiv, IObjectOf, Maybe, Pair } from "@thi.ng/api"; import type { EquivMapOpts } from "./api.js"; export declare class EquivMap<K, V> extends Map<K, V> implements Iterable<Pair<K, V>>, ICopy<EquivMap<K, V>>, IEmpty<EquivMap<K, V>>, IEquiv { #private; /** * Creates a new instance with optional initial key-value pairs and provided * options. If no `opts` are given, uses `ArraySet` for storing canonical * keys and * [`equiv`](https://docs.thi.ng/umbrella/equiv/functions/equiv.html) for * checking key equivalence. * * @param pairs - key-value pairs * @param opts - config options */ constructor(pairs?: Iterable<Pair<K, V>> | null, opts?: Partial<EquivMapOpts<K>>); [Symbol.iterator](): MapIterator<Pair<K, V>>; [Symbol.dispose](): void; get [Symbol.species](): typeof EquivMap; get [Symbol.toStringTag](): string; get size(): number; clear(): void; empty(): EquivMap<K, V>; copy(): EquivMap<K, V>; equiv(o: any): boolean; delete(key: K): boolean; dissoc(keys: Iterable<K>): this; /** * The key & value args given the callback `fn` MUST be treated as * readonly/immutable. This could be enforced via TS, but would * break ES6 Map interface contract. * * @param fn - * @param thisArg - */ forEach(fn: Fn3<V, K, Map<K, V>, void>, thisArg?: any): void; get(key: K, notFound?: V): Maybe<V>; has(key: K): boolean; set(key: K, value: V): this; into(pairs: Iterable<Pair<K, V>>): this; entries(): MapIterator<Pair<K, V>>; keys(): MapIterator<K>; values(): MapIterator<V>; opts(): EquivMapOpts<K>; } export declare function defEquivMap<K, V>(pairs?: Iterable<Pair<K, V>> | null, opts?: Partial<EquivMapOpts<K>>): EquivMap<K, V>; export declare function defEquivMap<V>(obj: IObjectOf<V>, opts?: Partial<EquivMapOpts<string>>): EquivMap<string, V>; //# sourceMappingURL=equiv-map.d.ts.map