Skip to content

Rename Stdlib functions from Exn to OrThrow #7554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
- `JSON.parseExn` → `JSON.parseOrThrow`
- Changed `BigInt.fromFloat` to return an option rather than throwing an error.
- Added `BigInt.fromFloatOrThrow`
- `Option.getExn` → `Option.getOrThrow`
- `Null.getExn` → `Null.getOrThrow`
- `Nullable.getExn` → `Nullable.getOrThrow`
- `Result.getExn` → `Result.getOrThrow`
- `List.getExn` → `List.getOrThrow`
- `List.tailExn` → `List.tailOrThrow`
- `List.headExn` → `List.headOrThrow`
- Old functions remain available but are marked as deprecated with guidance to use the new `OrThrow` variants.
- https://github.com/rescript-lang/rescript/pull/7518, https://github.com/rescript-lang/rescript/pull/7554

#### :rocket: New Feature

Expand Down
15 changes: 12 additions & 3 deletions lib/es6/Stdlib_List.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function head(x) {

}

function headExn(x) {
function headOrThrow(x) {
if (x !== 0) {
return x.hd;
}
Expand All @@ -28,7 +28,7 @@ function tail(x) {

}

function tailExn(x) {
function tailOrThrow(x) {
if (x !== 0) {
return x.tl;
}
Expand Down Expand Up @@ -67,7 +67,7 @@ function get(x, n) {
}
}

function getExn(x, n) {
function getOrThrow(x, n) {
if (n < 0) {
throw {
RE_EXN_ID: "Not_found",
Expand Down Expand Up @@ -1298,18 +1298,27 @@ function zip(l1, l2) {

let size = length;

let headExn = headOrThrow;

let tailExn = tailOrThrow;

let getExn = getOrThrow;

let toShuffled = shuffle;

export {
length,
size,
head,
headExn,
headOrThrow,
tail,
tailExn,
tailOrThrow,
add,
get,
getExn,
getOrThrow,
make,
fromInitializer,
shuffle,
Expand Down
7 changes: 5 additions & 2 deletions lib/es6/Stdlib_Null.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ function getOr(value, $$default) {
}
}

function getExn(value) {
function getOrThrow(value) {
if (value !== null) {
return value;
}
throw {
RE_EXN_ID: "Invalid_argument",
_1: "Null.getExn: value is null",
_1: "Null.getOrThrow: value is null",
Error: new Error()
};
}
Expand Down Expand Up @@ -71,6 +71,8 @@ function flatMap(value, f) {

let getWithDefault = getOr;

let getExn = getOrThrow;

let mapWithDefault = mapOr;

export {
Expand All @@ -80,6 +82,7 @@ export {
getOr,
getWithDefault,
getExn,
getOrThrow,
forEach,
map,
mapOr,
Expand Down
7 changes: 5 additions & 2 deletions lib/es6/Stdlib_Nullable.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ function getOr(value, $$default) {
}
}

function getExn(value) {
function getOrThrow(value) {
if (!(value == null)) {
return value;
}
throw {
RE_EXN_ID: "Invalid_argument",
_1: "Nullable.getExn: value is null or undefined",
_1: "Nullable.getOrThrow: value is null or undefined",
Error: new Error()
};
}
Expand Down Expand Up @@ -70,6 +70,8 @@ function flatMap(value, f) {

let getWithDefault = getOr;

let getExn = getOrThrow;

let mapWithDefault = mapOr;

export {
Expand All @@ -79,6 +81,7 @@ export {
getOr,
getWithDefault,
getExn,
getOrThrow,
forEach,
map,
mapOr,
Expand Down
7 changes: 5 additions & 2 deletions lib/es6/Stdlib_Option.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ function forEach(opt, f) {

}

function getExn(x, message) {
function getOrThrow(x, message) {
if (x !== undefined) {
return Primitive_option.valFromOption(x);
} else {
return Stdlib_Error.panic(message !== undefined ? message : "Option.getExn called for None value");
return Stdlib_Error.panic(message !== undefined ? message : "Option.getOrThrow called for None value");
}
}

Expand Down Expand Up @@ -197,6 +197,8 @@ function all6(param) {

}

let getExn = getOrThrow;

let mapWithDefault = mapOr;

let getWithDefault = getOr;
Expand All @@ -205,6 +207,7 @@ export {
filter,
forEach,
getExn,
getOrThrow,
mapOr,
mapWithDefault,
map,
Expand Down
5 changes: 4 additions & 1 deletion lib/es6/Stdlib_Result.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@



function getExn(x) {
function getOrThrow(x) {
if (x.TAG === "Ok") {
return x._0;
}
Expand Down Expand Up @@ -342,12 +342,15 @@ function all6(param) {
}
}

let getExn = getOrThrow;

let mapWithDefault = mapOr;

let getWithDefault = getOr;

export {
getExn,
getOrThrow,
mapOr,
mapWithDefault,
map,
Expand Down
15 changes: 12 additions & 3 deletions lib/js/Stdlib_List.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function head(x) {

}

function headExn(x) {
function headOrThrow(x) {
if (x !== 0) {
return x.hd;
}
Expand All @@ -28,7 +28,7 @@ function tail(x) {

}

function tailExn(x) {
function tailOrThrow(x) {
if (x !== 0) {
return x.tl;
}
Expand Down Expand Up @@ -67,7 +67,7 @@ function get(x, n) {
}
}

function getExn(x, n) {
function getOrThrow(x, n) {
if (n < 0) {
throw {
RE_EXN_ID: "Not_found",
Expand Down Expand Up @@ -1298,17 +1298,26 @@ function zip(l1, l2) {

let size = length;

let headExn = headOrThrow;

let tailExn = tailOrThrow;

let getExn = getOrThrow;

let toShuffled = shuffle;

exports.length = length;
exports.size = size;
exports.head = head;
exports.headExn = headExn;
exports.headOrThrow = headOrThrow;
exports.tail = tail;
exports.tailExn = tailExn;
exports.tailOrThrow = tailOrThrow;
exports.add = add;
exports.get = get;
exports.getExn = getExn;
exports.getOrThrow = getOrThrow;
exports.make = make;
exports.fromInitializer = fromInitializer;
exports.shuffle = shuffle;
Expand Down
7 changes: 5 additions & 2 deletions lib/js/Stdlib_Null.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ function getOr(value, $$default) {
}
}

function getExn(value) {
function getOrThrow(value) {
if (value !== null) {
return value;
}
throw {
RE_EXN_ID: "Invalid_argument",
_1: "Null.getExn: value is null",
_1: "Null.getOrThrow: value is null",
Error: new Error()
};
}
Expand Down Expand Up @@ -71,6 +71,8 @@ function flatMap(value, f) {

let getWithDefault = getOr;

let getExn = getOrThrow;

let mapWithDefault = mapOr;

exports.equal = equal;
Expand All @@ -79,6 +81,7 @@ exports.fromOption = fromOption;
exports.getOr = getOr;
exports.getWithDefault = getWithDefault;
exports.getExn = getExn;
exports.getOrThrow = getOrThrow;
exports.forEach = forEach;
exports.map = map;
exports.mapOr = mapOr;
Expand Down
7 changes: 5 additions & 2 deletions lib/js/Stdlib_Nullable.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ function getOr(value, $$default) {
}
}

function getExn(value) {
function getOrThrow(value) {
if (!(value == null)) {
return value;
}
throw {
RE_EXN_ID: "Invalid_argument",
_1: "Nullable.getExn: value is null or undefined",
_1: "Nullable.getOrThrow: value is null or undefined",
Error: new Error()
};
}
Expand Down Expand Up @@ -70,6 +70,8 @@ function flatMap(value, f) {

let getWithDefault = getOr;

let getExn = getOrThrow;

let mapWithDefault = mapOr;

exports.equal = equal;
Expand All @@ -78,6 +80,7 @@ exports.fromOption = fromOption;
exports.getOr = getOr;
exports.getWithDefault = getWithDefault;
exports.getExn = getExn;
exports.getOrThrow = getOrThrow;
exports.forEach = forEach;
exports.map = map;
exports.mapOr = mapOr;
Expand Down
7 changes: 5 additions & 2 deletions lib/js/Stdlib_Option.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ function forEach(opt, f) {

}

function getExn(x, message) {
function getOrThrow(x, message) {
if (x !== undefined) {
return Primitive_option.valFromOption(x);
} else {
return Stdlib_Error.panic(message !== undefined ? message : "Option.getExn called for None value");
return Stdlib_Error.panic(message !== undefined ? message : "Option.getOrThrow called for None value");
}
}

Expand Down Expand Up @@ -197,13 +197,16 @@ function all6(param) {

}

let getExn = getOrThrow;

let mapWithDefault = mapOr;

let getWithDefault = getOr;

exports.filter = filter;
exports.forEach = forEach;
exports.getExn = getExn;
exports.getOrThrow = getOrThrow;
exports.mapOr = mapOr;
exports.mapWithDefault = mapWithDefault;
exports.map = map;
Expand Down
5 changes: 4 additions & 1 deletion lib/js/Stdlib_Result.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';


function getExn(x) {
function getOrThrow(x) {
if (x.TAG === "Ok") {
return x._0;
}
Expand Down Expand Up @@ -342,11 +342,14 @@ function all6(param) {
}
}

let getExn = getOrThrow;

let mapWithDefault = mapOr;

let getWithDefault = getOr;

exports.getExn = getExn;
exports.getOrThrow = getOrThrow;
exports.mapOr = mapOr;
exports.mapWithDefault = mapWithDefault;
exports.map = map;
Expand Down
Loading