Skip to content

createComparatorBy

createComparatorBy<T>(…valueOfs): Comparator<T>

Defined in: packages/core/src/function/compare/create-comparator.ts:40

Builds a Comparator ordering items by one or more derived keys, each in ascending natural order, earlier keys taking priority over later ones.

Variadic rather than a traits object because the keys are homogeneous and their order is the priority; named fields would lose it.

For a key that needs its own ordering — descending, or anything but natural — compose instead: createChainedComparator(createComparatorBy(keyOf), createReversedComparator(createComparatorBy(otherKeyOf))).

T

…readonly [Callable<[T], unknown>, Callable<[T], unknown>]

Key accessors, in priority order. At least one is required.

Comparator<T>

A comparator calling one accessor per operand per key, at worst.