import { type ReadValueFunction } from './map'; import { type Maybe } from './maybe.type'; /** * A comparator that returns true if the two input values are considered equivalent. */ export type EqualityComparatorFunction = (a: T, b: T) => boolean; /** * Wraps an {@link EqualityComparatorFunction} to safely handle `Maybe` values. * * The wrapped function delegates to the comparator only when both values are non-nullish. * When both are nullish, it uses strict equality (`===`), so `null === null` is `true` * but `null === undefined` is `false`. * * @param compare - The comparator to wrap. * @returns A new comparator that handles nullish values safely before delegating to the wrapped comparator. * * @dbxUtil * @dbxUtilCategory value * @dbxUtilKind factory * @dbxUtilTags equal, equality, compare, comparator, maybe, safe, factory * @dbxUtilRelated safe-compare-equality * * @example * ```ts * const safeCompare = safeEqualityComparatorFunction((a: number, b: number) => a === b); * safeCompare(1, 1); // true * safeCompare(null, null); // true * safeCompare(null, undefined); // false * ``` * * @__NO_SIDE_EFFECTS__ */ export declare function safeEqualityComparatorFunction(compare: EqualityComparatorFunction): EqualityComparatorFunction>; /** * Convenience function that safely compares two `Maybe` values using the provided comparator. * * Delegates to {@link safeEqualityComparatorFunction} internally, so nullish values are handled * without invoking the comparator. * * @param a - First value to compare. * @param b - Second value to compare. * @param compare - The equality comparator for non-nullish values. * @returns `true` if the values are considered equal. * * @dbxUtil * @dbxUtilCategory value * @dbxUtilTags equal, equality, compare, maybe, safe * @dbxUtilRelated safe-equality-comparator-function * * @example * ```ts * safeCompareEquality(0, 1, (a, b) => a === b); * // false * * safeCompareEquality(null, null, (a, b) => a === b); * // true (comparator is not invoked) * ``` */ export declare function safeCompareEquality(a: Maybe, b: Maybe, compare: EqualityComparatorFunction): boolean; /** * Function used to compare the values from the input items. Items might not be defined. * * - If the items are both null or both undefined, the function will return true. * - If one is defined and one is undefined, it will return false. * - If one is undefined and one is null the function will return false. */ export type CompareEqualityWithValueFromItemsFunction = ((a: Maybe, b: Maybe) => boolean) & { /** * The function used to extract comparable values from each input item. */ readonly _readValues: ReadValueFunction; /** * The equality comparator applied to the extracted values. */ readonly _equalityComparator: EqualityComparatorFunction; }; /** * Creates a {@link CompareEqualityWithValueFromItemsFunction} that extracts values from items before comparing them. * * This is a convenience wrapper around {@link compareEqualityWithValueFromItemsFunctionFactory} that * accepts both the value reader and comparator in a single call. * * @param readValues - Extracts the comparable value from each item. * @param equalityComparator - Compares the extracted values for equality. * @returns Compares two items by their extracted values. * * @dbxUtil * @dbxUtilCategory value * @dbxUtilKind factory * @dbxUtilTags value, comparator, equality, factory, read * @dbxUtilRelated compare-equality-with-value-from-items-function-factory, safe-equality-comparator-function * * @__NO_SIDE_EFFECTS__ */ export declare function compareEqualityWithValueFromItemsFunction(readValues: ReadValueFunction, equalityComparator: EqualityComparatorFunction): CompareEqualityWithValueFromItemsFunction; /** * Function used to compare the values from the input items. Items might not be defined. */ export type CompareEqualityWithValueFromItemsFunctionFactory = ((equalityComparator: EqualityComparatorFunction) => CompareEqualityWithValueFromItemsFunction) & Pick, '_readValues'>; /** * Creates a {@link CompareEqualityWithValueFromItemsFunctionFactory} that is pre-configured with a value reader. * * The returned factory accepts different equality comparators, allowing reuse of the same value extraction logic * with varying comparison strategies. * * @param readValues - Extracts the comparable value from each item. * @returns A factory function that accepts an equality comparator and produces a comparison function. * * @dbxUtil * @dbxUtilCategory value * @dbxUtilKind factory * @dbxUtilTags value, comparator, equality, factory, read, reuse * @dbxUtilRelated compare-equality-with-value-from-items-function, safe-equality-comparator-function * * @example * ```ts * const factory = compareEqualityWithValueFromItemsFunctionFactory((x) => [x]); * const fn = factory(iterablesAreSetEquivalent); * * fn(0, 0); // true * fn(null, null); // true * fn(undefined, undefined); // true * fn(0, 1); // false * ``` * * @__NO_SIDE_EFFECTS__ */ export declare function compareEqualityWithValueFromItemsFunctionFactory(readValues: ReadValueFunction): CompareEqualityWithValueFromItemsFunctionFactory;