Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
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
12 changes: 9 additions & 3 deletions runtime/Stdlib_List.res
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,28 @@ let head = x =>
| list{x, ..._} => Some(x)
}

let headExn = x =>
let headOrThrow = x =>
switch x {
| list{} => throw(Not_found)
| list{x, ..._} => x
}

let headExn = headOrThrow

let tail = x =>
switch x {
| list{} => None
| list{_, ...xs} => Some(xs)
}

let tailExn = x =>
let tailOrThrow = x =>
switch x {
| list{} => throw(Not_found)
| list{_, ...t} => t
}

let tailExn = tailOrThrow

let add = (xs, x) => list{x, ...xs}

/* Assume `n >=0` */
Expand Down Expand Up @@ -156,13 +160,15 @@ let get = (x, n) =>
nthAux(x, n)
}

let getExn = (x, n) =>
let getOrThrow = (x, n) =>
if n < 0 {
throw(Not_found)
} else {
nthAuxAssert(x, n)
}

let getExn = getOrThrow

let rec partitionAux = (p, cell, precX, precY) =>
switch cell {
| list{} => ()
Expand Down
Loading