|
| 1 | +/** |
| 2 | +Ordering values represent the result of a comparison: `less`, `equal`, or `greater`. |
| 3 | +*/ |
1 | 4 | type t = float |
2 | 5 |
|
| 6 | +/** |
| 7 | +`less` is the ordering value returned when the left operand is smaller than the right operand. |
| 8 | +
|
| 9 | +## Examples |
| 10 | +
|
| 11 | +```rescript |
| 12 | +(1)->Int.compare(2) == Ordering.less |
| 13 | +``` |
| 14 | +*/ |
3 | 15 | @inline let less = -1. |
| 16 | + |
| 17 | +/** |
| 18 | +`equal` is the ordering value returned when two values compare the same. |
| 19 | +
|
| 20 | +## Examples |
| 21 | +
|
| 22 | +```rescript |
| 23 | +(2)->Int.compare(2) == Ordering.equal |
| 24 | +``` |
| 25 | +*/ |
4 | 26 | @inline let equal = 0. |
| 27 | + |
| 28 | +/** |
| 29 | +`greater` is the ordering value returned when the left operand is larger than the right operand. |
| 30 | +
|
| 31 | +## Examples |
| 32 | +
|
| 33 | +```rescript |
| 34 | +(3)->Int.compare(2) == Ordering.greater |
| 35 | +``` |
| 36 | +*/ |
5 | 37 | @inline let greater = 1. |
6 | 38 |
|
| 39 | +/** |
| 40 | +`isLess(ordering)` returns `true` when `ordering` equals `Ordering.less`. |
| 41 | +
|
| 42 | +## Examples |
| 43 | +
|
| 44 | +```rescript |
| 45 | +Ordering.isLess(Ordering.less) == true |
| 46 | +Ordering.isLess(Ordering.equal) == false |
| 47 | +``` |
| 48 | +*/ |
7 | 49 | let isLess = ord => ord < equal |
| 50 | + |
| 51 | +/** |
| 52 | +`isEqual(ordering)` returns `true` when `ordering` equals `Ordering.equal`. |
| 53 | +
|
| 54 | +## Examples |
| 55 | +
|
| 56 | +```rescript |
| 57 | +Ordering.isEqual(Ordering.equal) == true |
| 58 | +Ordering.isEqual(Ordering.greater) == false |
| 59 | +``` |
| 60 | +*/ |
8 | 61 | let isEqual = ord => ord == equal |
| 62 | + |
| 63 | +/** |
| 64 | +`isGreater(ordering)` returns `true` when `ordering` equals `Ordering.greater`. |
| 65 | +
|
| 66 | +## Examples |
| 67 | +
|
| 68 | +```rescript |
| 69 | +Ordering.isGreater(Ordering.greater) == true |
| 70 | +Ordering.isGreater(Ordering.less) == false |
| 71 | +``` |
| 72 | +*/ |
9 | 73 | let isGreater = ord => ord > equal |
10 | 74 |
|
| 75 | +/** |
| 76 | +`invert(ordering)` flips the ordering result (less becomes greater and vice versa). |
| 77 | +
|
| 78 | +## Examples |
| 79 | +
|
| 80 | +```rescript |
| 81 | +Ordering.invert(Ordering.less) == Ordering.greater |
| 82 | +Ordering.invert(Ordering.equal) == Ordering.equal |
| 83 | +``` |
| 84 | +*/ |
11 | 85 | let invert = ord => -.ord |
12 | 86 |
|
| 87 | +/** |
| 88 | +`fromInt(n)` converts an integer comparison result into an ordering. |
| 89 | +
|
| 90 | +## Examples |
| 91 | +
|
| 92 | +```rescript |
| 93 | +Ordering.fromInt(-5) == Ordering.less |
| 94 | +Ordering.fromInt(0) == Ordering.equal |
| 95 | +Ordering.fromInt(3) == Ordering.greater |
| 96 | +``` |
| 97 | +*/ |
13 | 98 | let fromInt = n => n < 0 ? less : n > 0 ? greater : equal |
14 | 99 |
|
15 | 100 | /** |
|
0 commit comments