(c1, c2, ...cRest)
| 434 | * @returns {Comparator<T>} comparator |
| 435 | */ |
| 436 | const concatComparators = (c1, c2, ...cRest) => { |
| 437 | if (cRest.length > 0) { |
| 438 | const [c3, ...cRest2] = cRest; |
| 439 | return concatComparators(c1, concatComparators(c2, c3, ...cRest2)); |
| 440 | } |
| 441 | const cacheEntry = /** @type {Comparator<T>} */ ( |
| 442 | concatComparatorsCache.get(c1, c2) |
| 443 | ); |
| 444 | if (cacheEntry !== undefined) return cacheEntry; |
| 445 | /** |
| 446 | * Returns compare result. |
| 447 | * @param {T} a first value |
| 448 | * @param {T} b second value |
| 449 | * @returns {-1 | 0 | 1} compare result |
| 450 | */ |
| 451 | const result = (a, b) => { |
| 452 | const res = c1(a, b); |
| 453 | if (res !== 0) return res; |
| 454 | return c2(a, b); |
| 455 | }; |
| 456 | concatComparatorsCache.set(c1, c2, result); |
| 457 | return result; |
| 458 | }; |
| 459 | |
| 460 | /** |
| 461 | * Defines the selector type used by this module. |
no test coverage detected