@thi.ng/associative
Version:
ES Map/Set-compatible implementations with customizable equality semantics & supporting operations
28 lines • 933 B
TypeScript
import { EquivMap } from "./equiv-map.js";
/**
* Takes an iterable of plain objects and array of indexing keys. Calls
* {@link selectKeysObj} on each value and uses returned objects as new keys
* to group original values. Returns a new {@link EquivMap} of sets.
*
* @example
* ```ts tangle:../export/indexed.ts
* import { indexed } from "@thi.ng/associative";
*
* console.log(
* "%s",
* indexed(
* new Set([{a: 1, b: 1}, {a: 1, b: 2}, {a: 1, b: 1, c: 2}]),
* ["a","b"]
* )
* );
* // EquivMap(2) {
* // { a: 1, b: 1 } => Set { { a: 1, b: 1 }, { a: 1, b: 1, c: 2 } },
* // { a: 1, b: 2 } => Set { { a: 1, b: 2 } }
* // }
* ```
*
* @param records - objects to index
* @param ks - keys used for indexing
*/
export declare const indexed: <T extends object>(records: Iterable<T>, ks: (keyof T)[]) => EquivMap<{ [id in keyof T]?: T[id] | undefined; }, Set<T>>;
//# sourceMappingURL=indexed.d.ts.map