Skip to content

Commit 7a6a135

Browse files
committed
Add Belt.Map.getOrThrow and Belt.MutableMap.getOrThrow
1 parent 0f6d3e1 commit 7a6a135

18 files changed

+63
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@
4949
- `List.headExn``List.headOrThrow`
5050
- `Belt.Array.getExn``Belt.Array.getOrThrow`
5151
- `Belt.Array.setExn``Belt.Array.setOrThrow`
52+
- `Belt.Map.getExn``Belt.Map.getOrThrow`
53+
- `Belt.MutableMap.getExn``Belt.MutableMap.getOrThrow`
5254
- Old functions remain available but are marked as deprecated with guidance to use the new `OrThrow` variants.
53-
- https://github.com/rescript-lang/rescript/pull/7518, https://github.com/rescript-lang/rescript/pull/7554
55+
- https://github.com/rescript-lang/rescript/pull/7518, https://github.com/rescript-lang/rescript/pull/7554, https://github.com/rescript-lang/rescript/pull/7581
5456

5557
#### :rocket: New Feature
5658

analysis/reanalyze/src/ExnLib.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
1212
let beltList =
1313
[("getExn", [notFound]); ("headExn", [notFound]); ("tailExn", [notFound])]
1414
in
15-
let beltMap = [("getExn", [notFound])] in
15+
let beltMap = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
1616
let beltMutableMap = beltMap in
1717
let beltMutableQueue = [("peekExn", [notFound]); ("popExn", [notFound])] in
1818
let beltMutableSet = [("getExn", [notFound])] in

lib/es6/Belt_Map.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ function getWithDefault(map, x, def) {
215215
return Belt_MapDict.getWithDefault(map.data, x, def, map.cmp);
216216
}
217217

218-
function getExn(map, x) {
219-
return Belt_MapDict.getExn(map.data, x, map.cmp);
218+
function getOrThrow(map, x) {
219+
return Belt_MapDict.getOrThrow(map.data, x, map.cmp);
220220
}
221221

222222
function has(map, x) {
@@ -273,6 +273,8 @@ let everyU = every;
273273

274274
let someU = some;
275275

276+
let getExn = getOrThrow;
277+
276278
let updateU = update;
277279

278280
let mergeU = merge;
@@ -324,6 +326,7 @@ export {
324326
getUndefined,
325327
getWithDefault,
326328
getExn,
329+
getOrThrow,
327330
remove,
328331
removeMany,
329332
set,

lib/es6/Belt_MapDict.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ let getUndefined = Belt_internalAVLtree.getUndefined;
326326

327327
let getWithDefault = Belt_internalAVLtree.getWithDefault;
328328

329-
let getExn = Belt_internalAVLtree.getExn;
329+
let getExn = Belt_internalAVLtree.getOrThrow;
330+
331+
let getOrThrow = Belt_internalAVLtree.getOrThrow;
330332

331333
let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal;
332334

@@ -386,6 +388,7 @@ export {
386388
getUndefined,
387389
getWithDefault,
388390
getExn,
391+
getOrThrow,
389392
checkInvariantInternal,
390393
remove,
391394
removeMany,

lib/es6/Belt_MutableMap.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ function getWithDefault(m, x, def) {
257257
return Belt_internalAVLtree.getWithDefault(m.data, x, def, m.cmp);
258258
}
259259

260-
function getExn(m, x) {
261-
return Belt_internalAVLtree.getExn(m.data, x, m.cmp);
260+
function getOrThrow(m, x) {
261+
return Belt_internalAVLtree.getOrThrow(m.data, x, m.cmp);
262262
}
263263

264264
function has(m, x) {
@@ -318,6 +318,8 @@ let everyU = every;
318318

319319
let someU = some;
320320

321+
let getExn = getOrThrow;
322+
321323
let updateU = update;
322324

323325
let mapU = map;
@@ -361,6 +363,7 @@ export {
361363
getUndefined,
362364
getWithDefault,
363365
getExn,
366+
getOrThrow,
364367
checkInvariantInternal,
365368
remove,
366369
removeMany,

lib/es6/Belt_internalAVLtree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ function getUndefined(_n, x, cmp) {
837837
};
838838
}
839839

840-
function getExn(_n, x, cmp) {
840+
function getOrThrow(_n, x, cmp) {
841841
while (true) {
842842
let n = _n;
843843
if (n !== undefined) {
@@ -1062,7 +1062,7 @@ export {
10621062
get,
10631063
getUndefined,
10641064
getWithDefault,
1065-
getExn,
1065+
getOrThrow,
10661066
has,
10671067
fromArray,
10681068
updateMutate,

lib/js/Belt_Map.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ function getWithDefault(map, x, def) {
215215
return Belt_MapDict.getWithDefault(map.data, x, def, map.cmp);
216216
}
217217

218-
function getExn(map, x) {
219-
return Belt_MapDict.getExn(map.data, x, map.cmp);
218+
function getOrThrow(map, x) {
219+
return Belt_MapDict.getOrThrow(map.data, x, map.cmp);
220220
}
221221

222222
function has(map, x) {
@@ -273,6 +273,8 @@ let everyU = every;
273273

274274
let someU = some;
275275

276+
let getExn = getOrThrow;
277+
276278
let updateU = update;
277279

278280
let mergeU = merge;
@@ -323,6 +325,7 @@ exports.get = get;
323325
exports.getUndefined = getUndefined;
324326
exports.getWithDefault = getWithDefault;
325327
exports.getExn = getExn;
328+
exports.getOrThrow = getOrThrow;
326329
exports.remove = remove;
327330
exports.removeMany = removeMany;
328331
exports.set = set;

lib/js/Belt_MapDict.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ let getUndefined = Belt_internalAVLtree.getUndefined;
326326

327327
let getWithDefault = Belt_internalAVLtree.getWithDefault;
328328

329-
let getExn = Belt_internalAVLtree.getExn;
329+
let getExn = Belt_internalAVLtree.getOrThrow;
330+
331+
let getOrThrow = Belt_internalAVLtree.getOrThrow;
330332

331333
let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal;
332334

@@ -385,6 +387,7 @@ exports.get = get;
385387
exports.getUndefined = getUndefined;
386388
exports.getWithDefault = getWithDefault;
387389
exports.getExn = getExn;
390+
exports.getOrThrow = getOrThrow;
388391
exports.checkInvariantInternal = checkInvariantInternal;
389392
exports.remove = remove;
390393
exports.removeMany = removeMany;

lib/js/Belt_MutableMap.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ function getWithDefault(m, x, def) {
257257
return Belt_internalAVLtree.getWithDefault(m.data, x, def, m.cmp);
258258
}
259259

260-
function getExn(m, x) {
261-
return Belt_internalAVLtree.getExn(m.data, x, m.cmp);
260+
function getOrThrow(m, x) {
261+
return Belt_internalAVLtree.getOrThrow(m.data, x, m.cmp);
262262
}
263263

264264
function has(m, x) {
@@ -318,6 +318,8 @@ let everyU = every;
318318

319319
let someU = some;
320320

321+
let getExn = getOrThrow;
322+
321323
let updateU = update;
322324

323325
let mapU = map;
@@ -360,6 +362,7 @@ exports.get = get;
360362
exports.getUndefined = getUndefined;
361363
exports.getWithDefault = getWithDefault;
362364
exports.getExn = getExn;
365+
exports.getOrThrow = getOrThrow;
363366
exports.checkInvariantInternal = checkInvariantInternal;
364367
exports.remove = remove;
365368
exports.removeMany = removeMany;

lib/js/Belt_internalAVLtree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ function getUndefined(_n, x, cmp) {
837837
};
838838
}
839839

840-
function getExn(_n, x, cmp) {
840+
function getOrThrow(_n, x, cmp) {
841841
while (true) {
842842
let n = _n;
843843
if (n !== undefined) {
@@ -1061,7 +1061,7 @@ exports.eq = eq;
10611061
exports.get = get;
10621062
exports.getUndefined = getUndefined;
10631063
exports.getWithDefault = getWithDefault;
1064-
exports.getExn = getExn;
1064+
exports.getOrThrow = getOrThrow;
10651065
exports.has = has;
10661066
exports.fromArray = fromArray;
10671067
exports.updateMutate = updateMutate;

0 commit comments

Comments
 (0)