@akala/core
Version:
28 lines (27 loc) • 1.53 kB
TypeScript
/**
* Removes duplicate elements from an array based on a comparison key or natural ordering
* @template T - Element type
* @param {T[]} array - Input array to process
* @param {((item: T) => any | number | bigint)} [distinctKey] - Function to extract comparison key from elements
* @param {boolean} [keepOrder=true] - Preserve original element order
* @returns {T[]} - Array with duplicates removed
*/
export declare function distinct<T>(array: T[], distinctKey?: (item: T) => any | number | bigint, keepOrder?: true): T[];
/**
* Specialized version of distinct for string comparisons
* @template T - Element type
* @param {T[]} array - Input array to process
* @param {((item: T) => string)} [distinctKey] - Function to extract string key from elements
* @param {boolean} [keepOrder=true] - Preserve original element order
* @returns {T[]} - Array with duplicates removed using string comparison
*/
export declare function distinctStrings<T>(array: T[], distinctKey?: (item: T) => string, keepOrder?: true): T[];
/**
* Core distinct implementation using custom comparison logic
* @template T - Element type
* @param {T[]} array - Input array to process
* @param {(a: T, b: T) => number} [compare] - Comparison function for ordering
* @param {boolean} [keepOrder=true] - Preserve original element order
* @returns {T[]} - Array with duplicates removed according to comparison logic
*/
export declare function distinctWithCompareFn<T>(array: T[], compare?: (a: T, b: T) => number, keepOrder?: true): T[];