[d24f17c] | 1 | import _curry1 from "./internal/_curry1.js";
|
---|
| 2 | /**
|
---|
| 3 | * Makes a comparator function out of a function that reports whether the first
|
---|
| 4 | * element is less than the second.
|
---|
| 5 | *
|
---|
| 6 | * @func
|
---|
| 7 | * @memberOf R
|
---|
| 8 | * @since v0.1.0
|
---|
| 9 | * @category Function
|
---|
| 10 | * @sig ((a, b) -> Boolean) -> ((a, b) -> Number)
|
---|
| 11 | * @param {Function} pred A predicate function of arity two which will return `true` if the first argument
|
---|
| 12 | * is less than the second, `false` otherwise
|
---|
| 13 | * @return {Function} A Function :: a -> b -> Int that returns `-1` if a < b, `1` if b < a, otherwise `0`
|
---|
| 14 | * @example
|
---|
| 15 | *
|
---|
| 16 | * const byAge = R.comparator((a, b) => a.age < b.age);
|
---|
| 17 | * const people = [
|
---|
| 18 | * { name: 'Emma', age: 70 },
|
---|
| 19 | * { name: 'Peter', age: 78 },
|
---|
| 20 | * { name: 'Mikhail', age: 62 },
|
---|
| 21 | * ];
|
---|
| 22 | * const peopleByIncreasingAge = R.sort(byAge, people);
|
---|
| 23 | * //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }]
|
---|
| 24 | */
|
---|
| 25 |
|
---|
| 26 | var comparator =
|
---|
| 27 | /*#__PURE__*/
|
---|
| 28 | _curry1(function comparator(pred) {
|
---|
| 29 | return function (a, b) {
|
---|
| 30 | return pred(a, b) ? -1 : pred(b, a) ? 1 : 0;
|
---|
| 31 | };
|
---|
| 32 | });
|
---|
| 33 |
|
---|
| 34 | export default comparator; |
---|