Skip to content

Commit f8d4636

Browse files
Ordering docstrings (#7981)
1 parent 77919a5 commit f8d4636

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

packages/@rescript/runtime/Stdlib_Ordering.res

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,100 @@
1+
/**
2+
Ordering values represent the result of a comparison: `less`, `equal`, or `greater`.
3+
*/
14
type t = float
25

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+
*/
315
@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+
*/
426
@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+
*/
537
@inline let greater = 1.
638

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+
*/
749
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+
*/
861
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+
*/
973
let isGreater = ord => ord > equal
1074

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+
*/
1185
let invert = ord => -.ord
1286

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+
*/
1398
let fromInt = n => n < 0 ? less : n > 0 ? greater : equal
1499

15100
/**

0 commit comments

Comments
 (0)