Skip to content

Commit 3f8e9a9

Browse files
committed
feat(nullable): add getExn
1 parent 4f2e82b commit 3f8e9a9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Core__Nullable.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@ function fromOption(option) {
99

1010
}
1111

12+
function getExn(value) {
13+
if (!(value == null)) {
14+
return value;
15+
}
16+
throw {
17+
RE_EXN_ID: "Invalid_argument",
18+
_1: "Nullable.getExn: value is null or undefined",
19+
Error: new Error()
20+
};
21+
}
22+
1223
export {
1324
fromOption ,
25+
getExn ,
1426
}
1527
/* No side effect */

src/Core__Nullable.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ let fromOption: option<'a> => t<'a> = option =>
1313
| Some(x) => make(x)
1414
| None => undefined
1515
}
16+
17+
let getExn: t<'a> => 'a = value =>
18+
switch value->toOption {
19+
| Some(x) => x
20+
| None => raise(Invalid_argument("Nullable.getExn: value is null or undefined"))
21+
}

0 commit comments

Comments
 (0)