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