Skip to content

Commit 0153b98

Browse files
committed
Rename Result.getExn
1 parent cc569a3 commit 0153b98

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

lib/es6/Stdlib_Result.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22

33

4-
function getExn(x) {
4+
function getOrThrow(x) {
55
if (x.TAG === "Ok") {
66
return x._0;
77
}
@@ -342,12 +342,15 @@ function all6(param) {
342342
}
343343
}
344344

345+
let getExn = getOrThrow;
346+
345347
let mapWithDefault = mapOr;
346348

347349
let getWithDefault = getOr;
348350

349351
export {
350352
getExn,
353+
getOrThrow,
351354
mapOr,
352355
mapWithDefault,
353356
map,

lib/js/Stdlib_Result.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33

4-
function getExn(x) {
4+
function getOrThrow(x) {
55
if (x.TAG === "Ok") {
66
return x._0;
77
}
@@ -342,11 +342,14 @@ function all6(param) {
342342
}
343343
}
344344

345+
let getExn = getOrThrow;
346+
345347
let mapWithDefault = mapOr;
346348

347349
let getWithDefault = getOr;
348350

349351
exports.getExn = getExn;
352+
exports.getOrThrow = getOrThrow;
350353
exports.mapOr = mapOr;
351354
exports.mapWithDefault = mapWithDefault;
352355
exports.map = map;

runtime/Stdlib_Result.res

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424
type t<'res, 'err> = result<'res, 'err> = Ok('res) | Error('err)
2525

26-
let getExn = x =>
26+
let getOrThrow = x =>
2727
switch x {
2828
| Ok(x) => x
2929
| Error(_) => throw(Not_found)
3030
}
3131

32+
let getExn = getOrThrow
33+
3234
let mapOr = (opt, default, f) =>
3335
switch opt {
3436
| Ok(x) => f(x)

runtime/Stdlib_Result.resi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,23 @@ type t<'res, 'err> = result<'res, 'err> = Ok('res) | Error('err)
5959
}
6060
```
6161
*/
62+
@deprecated("Use 'getOrThrow' instead")
6263
let getExn: result<'a, 'b> => 'a
6364

65+
/**
66+
`getOrThrow(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception
67+
68+
```res example
69+
Result.getOrThrow(Result.Ok(42)) == 42
70+
71+
switch Result.getOrThrow(Error("Invalid data")) {
72+
| exception Not_found => assert(true)
73+
| _ => assert(false)
74+
}
75+
```
76+
*/
77+
let getOrThrow: result<'a, 'b> => 'a
78+
6479
/**
6580
`mapOr(res, default, f)`: When res is `Ok(n)`, returns `f(n)`, otherwise `default`.
6681

0 commit comments

Comments
 (0)