/** * A Comparator defines a compare function enriched with methods to compose multiple * comparators in order to form complex comparison behavior. A compare function returns * negative numbers if the first value is lower than the second value, positive numbers * if the first value is larger than the second value and zero if both values are equal. */ export default class Comparator { readonly compare: (a: T, b: T) => number; constructor(compare: (a: T, b: T) => number); /** * Reverses the order of the current comparator. * * @returns {Comparator} */ reversed(): Comparator; /** * Composes the current comparator with the given comparison function such * that the latter is applied for every equal values of the former comparator. * * @param {(a: T, b: T) => number} nextComparison * @returns {Comparator} */ then(nextComparison: (a: T, b: T) => number): Comparator; /** * Composes the current comparator with the given comparison function such * that the latter is applied for every equal values of the current comparator * in reverse (descending) order. * * @param {(a: T, b: T) => number} nextComparison * @returns {Comparator} */ thenDescending(nextComparison: (a: T, b: T) => number): Comparator; /** * Composes the current comparator with a comparator which compares the properties * selected by the given `selector` function for every equal values of the current * comparator. * * @param {(value: T) => any} selector * @returns {Comparator} */ thenBy(selector: (value: T) => any): Comparator; /** * Composes the current comparator with a comparator which compares the values * of the given `key` for every equal values of the current comparator. * * @param {keyof T} key * @returns {Comparator} */ thenBy(key: keyof NonNullable): Comparator; /** * Composes the current comparator with a comparator which compares the properties * selected by the given `selector` function for every equal values of the current * comparator in reverse (descending) order. * * @param {(value: T) => any} selector * @returns {Comparator} */ thenByDescending(selector: (value: T) => any): Comparator; /** * Composes the current comparator with a comparator which compares the values * of the given `key` for every equal values of the current comparator * in reverse (descending) order. * * @param {keyof T} key * @returns {Comparator} */ thenByDescending(key: keyof NonNullable): Comparator; static naturalCompare(a: T, b: T, keyOrSelector?: ((item: T) => any) | keyof NonNullable): number; static naturalOrder(): Comparator; static reverseOrder(): Comparator; static nullsLast(): Comparator; static nullsFirst(): Comparator; }