Skip to content

Commit 43e5c68

Browse files
committed
Fix tests and add changelog
1 parent 00d730d commit 43e5c68

File tree

13 files changed

+101
-56
lines changed

13 files changed

+101
-56
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020
- `JSON.parseExn``JSON.parseOrThrow`
2121
- Changed `BigInt.fromFloat` to return an option rather than throwing an error.
2222
- Added `BigInt.fromFloatOrThrow`
23+
- `Option.getExn``Option.getOrThrow`
24+
- `Null.getExn``Null.getOrThrow`
25+
- `Nullable.getExn``Nullable.getOrThrow`
26+
- `Result.getExn``Result.getOrThrow`
27+
- `List.getExn``List.getOrThrow`
28+
- `List.tailExn``List.tailOrThrow`
29+
- `List.headExn``List.headOrThrow`
2330
- Old functions remain available but are marked as deprecated with guidance to use the new `OrThrow` variants.
31+
- https://github.com/rescript-lang/rescript/pull/7518, https://github.com/rescript-lang/rescript/pull/7554
2432

2533
#### :rocket: New Feature
2634

lib/es6/Stdlib_List.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function head(x) {
1111

1212
}
1313

14-
function headExn(x) {
14+
function headOrThrow(x) {
1515
if (x !== 0) {
1616
return x.hd;
1717
}
@@ -28,7 +28,7 @@ function tail(x) {
2828

2929
}
3030

31-
function tailExn(x) {
31+
function tailOrThrow(x) {
3232
if (x !== 0) {
3333
return x.tl;
3434
}
@@ -67,7 +67,7 @@ function get(x, n) {
6767
}
6868
}
6969

70-
function getExn(x, n) {
70+
function getOrThrow(x, n) {
7171
if (n < 0) {
7272
throw {
7373
RE_EXN_ID: "Not_found",
@@ -1298,18 +1298,27 @@ function zip(l1, l2) {
12981298

12991299
let size = length;
13001300

1301+
let headExn = headOrThrow;
1302+
1303+
let tailExn = tailOrThrow;
1304+
1305+
let getExn = getOrThrow;
1306+
13011307
let toShuffled = shuffle;
13021308

13031309
export {
13041310
length,
13051311
size,
13061312
head,
13071313
headExn,
1314+
headOrThrow,
13081315
tail,
13091316
tailExn,
1317+
tailOrThrow,
13101318
add,
13111319
get,
13121320
getExn,
1321+
getOrThrow,
13131322
make,
13141323
fromInitializer,
13151324
shuffle,

lib/es6/Stdlib_Null.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ function getOr(value, $$default) {
2727
}
2828
}
2929

30-
function getExn(value) {
30+
function getOrThrow(value) {
3131
if (value !== null) {
3232
return value;
3333
}
3434
throw {
3535
RE_EXN_ID: "Invalid_argument",
36-
_1: "Null.getExn: value is null",
36+
_1: "Null.getOrThrow: value is null",
3737
Error: new Error()
3838
};
3939
}
@@ -71,6 +71,8 @@ function flatMap(value, f) {
7171

7272
let getWithDefault = getOr;
7373

74+
let getExn = getOrThrow;
75+
7476
let mapWithDefault = mapOr;
7577

7678
export {
@@ -80,6 +82,7 @@ export {
8082
getOr,
8183
getWithDefault,
8284
getExn,
85+
getOrThrow,
8386
forEach,
8487
map,
8588
mapOr,

lib/es6/Stdlib_Nullable.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ function getOr(value, $$default) {
2626
}
2727
}
2828

29-
function getExn(value) {
29+
function getOrThrow(value) {
3030
if (!(value == null)) {
3131
return value;
3232
}
3333
throw {
3434
RE_EXN_ID: "Invalid_argument",
35-
_1: "Nullable.getExn: value is null or undefined",
35+
_1: "Nullable.getOrThrow: value is null or undefined",
3636
Error: new Error()
3737
};
3838
}
@@ -70,6 +70,8 @@ function flatMap(value, f) {
7070

7171
let getWithDefault = getOr;
7272

73+
let getExn = getOrThrow;
74+
7375
let mapWithDefault = mapOr;
7476

7577
export {
@@ -79,6 +81,7 @@ export {
7981
getOr,
8082
getWithDefault,
8183
getExn,
84+
getOrThrow,
8285
forEach,
8386
map,
8487
mapOr,

lib/es6/Stdlib_Option.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ function forEach(opt, f) {
1717

1818
}
1919

20-
function getExn(x, message) {
20+
function getOrThrow(x, message) {
2121
if (x !== undefined) {
2222
return Primitive_option.valFromOption(x);
2323
} else {
24-
return Stdlib_Error.panic(message !== undefined ? message : "Option.getExn called for None value");
24+
return Stdlib_Error.panic(message !== undefined ? message : "Option.getOrThrow called for None value");
2525
}
2626
}
2727

@@ -197,6 +197,8 @@ function all6(param) {
197197

198198
}
199199

200+
let getExn = getOrThrow;
201+
200202
let mapWithDefault = mapOr;
201203

202204
let getWithDefault = getOr;
@@ -205,6 +207,7 @@ export {
205207
filter,
206208
forEach,
207209
getExn,
210+
getOrThrow,
208211
mapOr,
209212
mapWithDefault,
210213
map,

lib/js/Stdlib_List.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function head(x) {
1111

1212
}
1313

14-
function headExn(x) {
14+
function headOrThrow(x) {
1515
if (x !== 0) {
1616
return x.hd;
1717
}
@@ -28,7 +28,7 @@ function tail(x) {
2828

2929
}
3030

31-
function tailExn(x) {
31+
function tailOrThrow(x) {
3232
if (x !== 0) {
3333
return x.tl;
3434
}
@@ -67,7 +67,7 @@ function get(x, n) {
6767
}
6868
}
6969

70-
function getExn(x, n) {
70+
function getOrThrow(x, n) {
7171
if (n < 0) {
7272
throw {
7373
RE_EXN_ID: "Not_found",
@@ -1298,17 +1298,26 @@ function zip(l1, l2) {
12981298

12991299
let size = length;
13001300

1301+
let headExn = headOrThrow;
1302+
1303+
let tailExn = tailOrThrow;
1304+
1305+
let getExn = getOrThrow;
1306+
13011307
let toShuffled = shuffle;
13021308

13031309
exports.length = length;
13041310
exports.size = size;
13051311
exports.head = head;
13061312
exports.headExn = headExn;
1313+
exports.headOrThrow = headOrThrow;
13071314
exports.tail = tail;
13081315
exports.tailExn = tailExn;
1316+
exports.tailOrThrow = tailOrThrow;
13091317
exports.add = add;
13101318
exports.get = get;
13111319
exports.getExn = getExn;
1320+
exports.getOrThrow = getOrThrow;
13121321
exports.make = make;
13131322
exports.fromInitializer = fromInitializer;
13141323
exports.shuffle = shuffle;

lib/js/Stdlib_Null.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ function getOr(value, $$default) {
2727
}
2828
}
2929

30-
function getExn(value) {
30+
function getOrThrow(value) {
3131
if (value !== null) {
3232
return value;
3333
}
3434
throw {
3535
RE_EXN_ID: "Invalid_argument",
36-
_1: "Null.getExn: value is null",
36+
_1: "Null.getOrThrow: value is null",
3737
Error: new Error()
3838
};
3939
}
@@ -71,6 +71,8 @@ function flatMap(value, f) {
7171

7272
let getWithDefault = getOr;
7373

74+
let getExn = getOrThrow;
75+
7476
let mapWithDefault = mapOr;
7577

7678
exports.equal = equal;
@@ -79,6 +81,7 @@ exports.fromOption = fromOption;
7981
exports.getOr = getOr;
8082
exports.getWithDefault = getWithDefault;
8183
exports.getExn = getExn;
84+
exports.getOrThrow = getOrThrow;
8285
exports.forEach = forEach;
8386
exports.map = map;
8487
exports.mapOr = mapOr;

lib/js/Stdlib_Nullable.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ function getOr(value, $$default) {
2626
}
2727
}
2828

29-
function getExn(value) {
29+
function getOrThrow(value) {
3030
if (!(value == null)) {
3131
return value;
3232
}
3333
throw {
3434
RE_EXN_ID: "Invalid_argument",
35-
_1: "Nullable.getExn: value is null or undefined",
35+
_1: "Nullable.getOrThrow: value is null or undefined",
3636
Error: new Error()
3737
};
3838
}
@@ -70,6 +70,8 @@ function flatMap(value, f) {
7070

7171
let getWithDefault = getOr;
7272

73+
let getExn = getOrThrow;
74+
7375
let mapWithDefault = mapOr;
7476

7577
exports.equal = equal;
@@ -78,6 +80,7 @@ exports.fromOption = fromOption;
7880
exports.getOr = getOr;
7981
exports.getWithDefault = getWithDefault;
8082
exports.getExn = getExn;
83+
exports.getOrThrow = getOrThrow;
8184
exports.forEach = forEach;
8285
exports.map = map;
8386
exports.mapOr = mapOr;

lib/js/Stdlib_Option.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ function forEach(opt, f) {
1717

1818
}
1919

20-
function getExn(x, message) {
20+
function getOrThrow(x, message) {
2121
if (x !== undefined) {
2222
return Primitive_option.valFromOption(x);
2323
} else {
24-
return Stdlib_Error.panic(message !== undefined ? message : "Option.getExn called for None value");
24+
return Stdlib_Error.panic(message !== undefined ? message : "Option.getOrThrow called for None value");
2525
}
2626
}
2727

@@ -197,13 +197,16 @@ function all6(param) {
197197

198198
}
199199

200+
let getExn = getOrThrow;
201+
200202
let mapWithDefault = mapOr;
201203

202204
let getWithDefault = getOr;
203205

204206
exports.filter = filter;
205207
exports.forEach = forEach;
206208
exports.getExn = getExn;
209+
exports.getOrThrow = getOrThrow;
207210
exports.mapOr = mapOr;
208211
exports.mapWithDefault = mapWithDefault;
209212
exports.map = map;

runtime/Stdlib_List.resi

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,22 @@ switch List.tailExn(list{}) {
149149
let tailExn: list<'a> => list<'a>
150150

151151
/**
152-
`tailOrThrow(list)` same as [`tail`](#tail).
153-
Raises an Error if list is empty.
152+
`tailOrThrow(list)` same as [`tail`](#tail).
154153
155-
## Examples
156-
```res
157-
List.tailOrThrow(list{1, 2, 3})->assertEqual(list{2, 3})
154+
## Examples
155+
156+
```rescript
157+
List.tailOrThrow(list{1, 2, 3})->assertEqual(list{2, 3})
158158
159-
switch List.tailOrThrow(list{}) {
160-
| _ => Console.log("never happens")
161-
| exception _ => Console.log("error")
162-
}
163-
```
159+
switch List.tailOrThrow(list{}) {
160+
| exception Not_found => assert(true)
161+
| _ => assert(false)
162+
}
163+
```
164+
165+
## Exceptions
166+
167+
- Raises an Error if list is empty.
164168
*/
165169
let tailOrThrow: list<'a> => list<'a>
166170

@@ -219,19 +223,26 @@ switch abc->List.getExn(4) {
219223
let getExn: (list<'a>, int) => 'a
220224

221225
/**
222-
`getOrThrow(list, index)` same as [`get`](#get).
223-
Raises an Error if `index` is larger than the length of list.
226+
`getOrThrow(list, index)` same as [`get`](#get).
227+
228+
## Examples
224229
225-
## Examples
226-
```res
227-
let abc = list{"A", "B", "C"}
228-
abc->List.getOrThrow(1)->assertEqual("B")
230+
```rescript
231+
let abc = list{"A", "B", "C"}
229232
230-
switch abc->List.getOrThrow(4) {
231-
| _ => Console.log("never happens")
232-
| exception _ => Console.log("error")
233-
}
234-
```
233+
abc
234+
->List.getOrThrow(1)
235+
->assertEqual("B")
236+
237+
switch abc->List.getOrThrow(4) {
238+
| exception Not_found => assert(true)
239+
| _ => assert(false)
240+
}
241+
```
242+
243+
## Exceptions
244+
245+
- Raises an Error if `index` is larger than the length of list.
235246
*/
236247
let getOrThrow: (list<'a>, int) => 'a
237248

0 commit comments

Comments
 (0)