Skip to content

Commit f1e4a1e

Browse files
committed
Add Belt.Set.getOrThrow and Belt.MutableSet.getOrThrow
1 parent 7a6a135 commit f1e4a1e

14 files changed

+46
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
- `Belt.Array.setExn``Belt.Array.setOrThrow`
5252
- `Belt.Map.getExn``Belt.Map.getOrThrow`
5353
- `Belt.MutableMap.getExn``Belt.MutableMap.getOrThrow`
54+
- `Belt.Set.getExn``Belt.Set.getOrThrow`
55+
- `Belt.MutableSet.getExn``Belt.MutableSet.getOrThrow`
5456
- Old functions remain available but are marked as deprecated with guidance to use the new `OrThrow` variants.
5557
- https://github.com/rescript-lang/rescript/pull/7518, https://github.com/rescript-lang/rescript/pull/7554, https://github.com/rescript-lang/rescript/pull/7581
5658

analysis/reanalyze/src/ExnLib.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
1515
let beltMap = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
1616
let beltMutableMap = beltMap in
1717
let beltMutableQueue = [("peekExn", [notFound]); ("popExn", [notFound])] in
18-
let beltMutableSet = [("getExn", [notFound])] in
18+
let beltSet = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
19+
let beltMutableSet = beltSet in
1920
let beltOption = [("getExn", [notFound])] in
2021
let beltResult = [("getExn", [notFound])] in
21-
let beltSet = [("getExn", [notFound])] in
2222
let bsJson =
2323
(* bs-json *)
2424
[

lib/es6/Belt_MutableSet.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ function getUndefined(d, x) {
276276
return Belt_internalAVLset.getUndefined(d.data, x, d.cmp);
277277
}
278278

279-
function getExn(d, x) {
280-
return Belt_internalAVLset.getExn(d.data, x, d.cmp);
279+
function getOrThrow(d, x) {
280+
return Belt_internalAVLset.getOrThrow(d.data, x, d.cmp);
281281
}
282282

283283
function split(d, key) {
@@ -477,6 +477,8 @@ let keepU = keep;
477477

478478
let partitionU = partition;
479479

480+
let getExn = getOrThrow;
481+
480482
export {
481483
Int,
482484
$$String,
@@ -520,6 +522,7 @@ export {
520522
get,
521523
getUndefined,
522524
getExn,
525+
getOrThrow,
523526
split,
524527
checkInvariantInternal,
525528
}

lib/es6/Belt_SetDict.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ let get = Belt_internalAVLset.get;
314314

315315
let getUndefined = Belt_internalAVLset.getUndefined;
316316

317-
let getExn = Belt_internalAVLset.getExn;
317+
let getExn = Belt_internalAVLset.getOrThrow;
318+
319+
let getOrThrow = Belt_internalAVLset.getOrThrow;
318320

319321
let checkInvariantInternal = Belt_internalAVLset.checkInvariantInternal;
320322

@@ -356,6 +358,7 @@ export {
356358
get,
357359
getUndefined,
358360
getExn,
361+
getOrThrow,
359362
split,
360363
checkInvariantInternal,
361364
}

lib/es6/Belt_internalAVLset.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ function getUndefined(_n, x, cmp) {
688688
};
689689
}
690690

691-
function getExn(_n, x, cmp) {
691+
function getOrThrow(_n, x, cmp) {
692692
while (true) {
693693
let n = _n;
694694
if (n !== undefined) {
@@ -877,7 +877,7 @@ export {
877877
subset,
878878
get,
879879
getUndefined,
880-
getExn,
880+
getOrThrow,
881881
fromArray,
882882
addMutate,
883883
balMutate,

lib/js/Belt_MutableSet.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ function getUndefined(d, x) {
276276
return Belt_internalAVLset.getUndefined(d.data, x, d.cmp);
277277
}
278278

279-
function getExn(d, x) {
280-
return Belt_internalAVLset.getExn(d.data, x, d.cmp);
279+
function getOrThrow(d, x) {
280+
return Belt_internalAVLset.getOrThrow(d.data, x, d.cmp);
281281
}
282282

283283
function split(d, key) {
@@ -477,6 +477,8 @@ let keepU = keep;
477477

478478
let partitionU = partition;
479479

480+
let getExn = getOrThrow;
481+
480482
exports.Int = Int;
481483
exports.$$String = $$String;
482484
exports.make = make;
@@ -519,6 +521,7 @@ exports.maxUndefined = maxUndefined;
519521
exports.get = get;
520522
exports.getUndefined = getUndefined;
521523
exports.getExn = getExn;
524+
exports.getOrThrow = getOrThrow;
522525
exports.split = split;
523526
exports.checkInvariantInternal = checkInvariantInternal;
524527
/* No side effect */

lib/js/Belt_SetDict.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ let get = Belt_internalAVLset.get;
314314

315315
let getUndefined = Belt_internalAVLset.getUndefined;
316316

317-
let getExn = Belt_internalAVLset.getExn;
317+
let getExn = Belt_internalAVLset.getOrThrow;
318+
319+
let getOrThrow = Belt_internalAVLset.getOrThrow;
318320

319321
let checkInvariantInternal = Belt_internalAVLset.checkInvariantInternal;
320322

@@ -355,6 +357,7 @@ exports.maxUndefined = maxUndefined;
355357
exports.get = get;
356358
exports.getUndefined = getUndefined;
357359
exports.getExn = getExn;
360+
exports.getOrThrow = getOrThrow;
358361
exports.split = split;
359362
exports.checkInvariantInternal = checkInvariantInternal;
360363
/* No side effect */

lib/js/Belt_internalAVLset.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ function getUndefined(_n, x, cmp) {
688688
};
689689
}
690690

691-
function getExn(_n, x, cmp) {
691+
function getOrThrow(_n, x, cmp) {
692692
while (true) {
693693
let n = _n;
694694
if (n !== undefined) {
@@ -876,7 +876,7 @@ exports.eq = eq;
876876
exports.subset = subset;
877877
exports.get = get;
878878
exports.getUndefined = getUndefined;
879-
exports.getExn = getExn;
879+
exports.getOrThrow = getOrThrow;
880880
exports.fromArray = fromArray;
881881
exports.addMutate = addMutate;
882882
exports.balMutate = balMutate;

runtime/Belt_MutableSet.res

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ let get = (d, x) => N.get(~cmp=d.cmp, d.data, x)
235235

236236
let getUndefined = (d, x) => N.getUndefined(~cmp=d.cmp, d.data, x)
237237

238-
let getExn = (d, x) => N.getExn(~cmp=d.cmp, d.data, x)
238+
let getOrThrow = (d, x) => N.getOrThrow(~cmp=d.cmp, d.data, x)
239+
240+
let getExn = getOrThrow
239241

240242
let split = (d, key) => {
241243
let arr = N.toArray(d.data)

runtime/Belt_MutableSet.resi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,14 @@ let getUndefined: (t<'value, 'id>, 'value) => Js.undefined<'value>
637637
/**
638638
Same as `Belt.MutableSet.get` but raise when element does not exist.
639639
*/
640+
@deprecated("Use `getOrThrow` instead")
640641
let getExn: (t<'value, 'id>, 'value) => 'value
641642

643+
/**
644+
Same as `Belt.MutableSet.get` but raise when element does not exist.
645+
*/
646+
let getOrThrow: (t<'value, 'id>, 'value) => 'value
647+
642648
/**
643649
Returns a tuple `((smaller, larger), present)`, `present` is true when element exist in set.
644650

0 commit comments

Comments
 (0)