UNPKG

@thi.ng/associative

Version:

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

58 lines 2.2 kB
import type { Fn3, Maybe, Pair } from "@thi.ng/api"; import type { EquivSetOpts, IEquivSet } from "./api.js"; /** * An alternative set implementation to the native ES6 Set type. Uses * customizable equality/equivalence predicate and so is more useful when * dealing with structured data. Implements full API of native Set and by the * default uses * [`equiv`](https://docs.thi.ng/umbrella/equiv/functions/equiv.html) for * equivalence checking. * * Additionally, the type also implements the * [`ICopy`](https://docs.thi.ng/umbrella/api/interfaces/ICopy.html), * [`IEmpty`](https://docs.thi.ng/umbrella/api/interfaces/IEmpty.html) and * [`IEquiv`](https://docs.thi.ng/umbrella/api/interfaces/IEquiv.html) * interfaces itself. */ export declare class ArraySet<T> extends Set<T> implements IEquivSet<T> { #private; constructor(vals?: Iterable<T> | null, opts?: Partial<EquivSetOpts<T>>); [Symbol.iterator](): SetIterator<T>; [Symbol.dispose](): void; get [Symbol.species](): typeof ArraySet; get [Symbol.toStringTag](): string; get size(): number; copy(): ArraySet<T>; empty(): ArraySet<T>; clear(): void; first(): Maybe<T>; add(key: T): this; into(keys: Iterable<T>): this; has(key: T): boolean; /** * Returns the canonical value for `x`, if present. If the set * contains no equivalent for `x`, returns `notFound`. * * @param key - search key * @param notFound - default value */ get(key: T, notFound?: T): Maybe<T>; delete(key: T): boolean; disj(keys: Iterable<T>): this; equiv(o: any): boolean; /** * The value args given to the callback `fn` MUST be treated as * readonly/immutable. This could be enforced via TS, but would * break ES6 Set interface contract. * * @param fn - * @param thisArg - */ forEach(fn: Fn3<T, T, Set<T>, void>, thisArg?: any): void; entries(): SetIterator<Pair<T, T>>; keys(): SetIterator<T>; values(): SetIterator<T>; opts(): EquivSetOpts<T>; } export declare const defArraySet: <T>(vals?: Iterable<T> | null, opts?: Partial<EquivSetOpts<T>>) => ArraySet<T>; //# sourceMappingURL=array-set.d.ts.map