From 0f6d3e18726b9f2458b6ad33112c4adf5f355cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Sat, 28 Jun 2025 21:23:59 +0100 Subject: [PATCH 01/10] Add Belt.Array.getOrThrow and setOrThrow --- CHANGELOG.md | 2 ++ analysis/reanalyze/src/ExnLib.ml | 9 ++++++++- lib/es6/Belt_Array.js | 12 +++++++++--- lib/js/Belt_Array.js | 12 +++++++++--- rewatch/testrepo/packages/dep02/src/Array.mjs | 6 ++++++ runtime/Belt_Array.res | 8 ++++++-- runtime/Belt_Array.resi | 13 +++++++++++++ tests/tests/src/module_missing_conversion.mjs | 2 ++ tests/tests/src/test_simple_include.mjs | 6 ++++++ 9 files changed, 61 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42c9ddd72e..1947906d56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ - `List.getExn` → `List.getOrThrow` - `List.tailExn` → `List.tailOrThrow` - `List.headExn` → `List.headOrThrow` + - `Belt.Array.getExn` → `Belt.Array.getOrThrow` + - `Belt.Array.setExn` → `Belt.Array.setOrThrow` - 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 diff --git a/analysis/reanalyze/src/ExnLib.ml b/analysis/reanalyze/src/ExnLib.ml index 0903b54e0e..710b3d3f61 100644 --- a/analysis/reanalyze/src/ExnLib.ml +++ b/analysis/reanalyze/src/ExnLib.ml @@ -1,7 +1,14 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t = let table = Hashtbl.create 15 in let open Exn in - let beltArray = [("getExn", [assertFailure]); ("setExn", [assertFailure])] in + let beltArray = + [ + ("getExn", [assertFailure]); + ("getOrThrow", [assertFailure]); + ("setExn", [assertFailure]); + ("setOrThrow", [assertFailure]); + ] + in let beltList = [("getExn", [notFound]); ("headExn", [notFound]); ("tailExn", [notFound])] in diff --git a/lib/es6/Belt_Array.js b/lib/es6/Belt_Array.js index 3d19ea8a77..9dda9f0634 100644 --- a/lib/es6/Belt_Array.js +++ b/lib/es6/Belt_Array.js @@ -10,7 +10,7 @@ function get(arr, i) { } -function getExn(arr, i) { +function getOrThrow(arr, i) { if (!(i >= 0 && i < arr.length)) { throw { RE_EXN_ID: "Assert_failure", @@ -34,13 +34,13 @@ function set(arr, i, v) { } } -function setExn(arr, i, v) { +function setOrThrow(arr, i, v) { if (!(i >= 0 && i < arr.length)) { throw { RE_EXN_ID: "Assert_failure", _1: [ "Belt_Array.res", - 49, + 51, 2 ], Error: new Error() @@ -582,6 +582,10 @@ function init(n, f) { return v; } +let getExn = getOrThrow; + +let setExn = setOrThrow; + let makeByU = makeBy; let makeByAndShuffleU = makeByAndShuffle; @@ -637,8 +641,10 @@ let initU = init; export { get, getExn, + getOrThrow, set, setExn, + setOrThrow, shuffleInPlace, shuffle, reverseInPlace, diff --git a/lib/js/Belt_Array.js b/lib/js/Belt_Array.js index b619efe8c5..821fcc18df 100644 --- a/lib/js/Belt_Array.js +++ b/lib/js/Belt_Array.js @@ -10,7 +10,7 @@ function get(arr, i) { } -function getExn(arr, i) { +function getOrThrow(arr, i) { if (!(i >= 0 && i < arr.length)) { throw { RE_EXN_ID: "Assert_failure", @@ -34,13 +34,13 @@ function set(arr, i, v) { } } -function setExn(arr, i, v) { +function setOrThrow(arr, i, v) { if (!(i >= 0 && i < arr.length)) { throw { RE_EXN_ID: "Assert_failure", _1: [ "Belt_Array.res", - 49, + 51, 2 ], Error: new Error() @@ -582,6 +582,10 @@ function init(n, f) { return v; } +let getExn = getOrThrow; + +let setExn = setOrThrow; + let makeByU = makeBy; let makeByAndShuffleU = makeByAndShuffle; @@ -636,8 +640,10 @@ let initU = init; exports.get = get; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.set = set; exports.setExn = setExn; +exports.setOrThrow = setOrThrow; exports.shuffleInPlace = shuffleInPlace; exports.shuffle = shuffle; exports.reverseInPlace = reverseInPlace; diff --git a/rewatch/testrepo/packages/dep02/src/Array.mjs b/rewatch/testrepo/packages/dep02/src/Array.mjs index 35d0ba58a2..592f4faf9c 100644 --- a/rewatch/testrepo/packages/dep02/src/Array.mjs +++ b/rewatch/testrepo/packages/dep02/src/Array.mjs @@ -291,10 +291,14 @@ let get = Belt_Array.get; let getExn = Belt_Array.getExn; +let getOrThrow = Belt_Array.getOrThrow; + let set = Belt_Array.set; let setExn = Belt_Array.setExn; +let setOrThrow = Belt_Array.setOrThrow; + let shuffleInPlace = Belt_Array.shuffleInPlace; let shuffle = Belt_Array.shuffle; @@ -434,8 +438,10 @@ let sortByRaw = Belt_SortArray.stableSortBy; export { get, getExn, + getOrThrow, set, setExn, + setOrThrow, shuffleInPlace, shuffle, reverseInPlace, diff --git a/runtime/Belt_Array.res b/runtime/Belt_Array.res index 5700b4b047..9c1025e1dd 100644 --- a/runtime/Belt_Array.res +++ b/runtime/Belt_Array.res @@ -32,11 +32,13 @@ let get = (arr, i) => None } -let getExn = (arr, i) => { +let getOrThrow = (arr, i) => { assert(i >= 0 && i < length(arr)) getUnsafe(arr, i) } +let getExn = getOrThrow + let set = (arr, i, v) => if i >= 0 && i < length(arr) { setUnsafe(arr, i, v) @@ -45,11 +47,13 @@ let set = (arr, i, v) => false } -let setExn = (arr, i, v) => { +let setOrThrow = (arr, i, v) => { assert(i >= 0 && i < length(arr)) setUnsafe(arr, i, v) } +let setExn = setOrThrow + @set external truncateToLengthUnsafe: (t<'a>, int) => unit = "length" @new external makeUninitialized: int => array> = "Array" diff --git a/runtime/Belt_Array.resi b/runtime/Belt_Array.resi index bac8001f31..a72d31fa8e 100644 --- a/runtime/Belt_Array.resi +++ b/runtime/Belt_Array.resi @@ -50,8 +50,15 @@ let get: (t<'a>, int) => option<'a> Raise an exception if `i` is out of range. Otherwise return the value at index `i` in `arr`. */ +@deprecated("Use 'getOrThrow' instead") let getExn: (t<'a>, int) => 'a +/** +Raise an exception if `i` is out of range. +Otherwise return the value at index `i` in `arr`. +*/ +let getOrThrow: (t<'a>, int) => 'a + /** `getUnsafe(arr, i)` @@ -79,8 +86,14 @@ let set: (t<'a>, int, 'a) => bool /** `setExn(arr, i, x)` raise an exception if `i` is out of range. */ +@deprecated("Use 'setOrThrow' instead") let setExn: (t<'a>, int, 'a) => unit +/** +`setOrThrow(arr, i, x)` raise an exception if `i` is out of range. +*/ +let setOrThrow: (t<'a>, int, 'a) => unit + external setUnsafe: (t<'a>, int, 'a) => unit = "%array_unsafe_set" /** diff --git a/tests/tests/src/module_missing_conversion.mjs b/tests/tests/src/module_missing_conversion.mjs index c73348c99a..e9512c212e 100644 --- a/tests/tests/src/module_missing_conversion.mjs +++ b/tests/tests/src/module_missing_conversion.mjs @@ -10,8 +10,10 @@ function f(x) { let XX = { get: Belt_Array.get, getExn: Belt_Array.getExn, + getOrThrow: Belt_Array.getOrThrow, set: Belt_Array.set, setExn: Belt_Array.setExn, + setOrThrow: Belt_Array.setOrThrow, shuffleInPlace: Belt_Array.shuffleInPlace, shuffle: Belt_Array.shuffle, reverseInPlace: Belt_Array.reverseInPlace, diff --git a/tests/tests/src/test_simple_include.mjs b/tests/tests/src/test_simple_include.mjs index 0d04e52126..1fce783ad7 100644 --- a/tests/tests/src/test_simple_include.mjs +++ b/tests/tests/src/test_simple_include.mjs @@ -26,10 +26,14 @@ let get = Belt_Array.get; let getExn = Belt_Array.getExn; +let getOrThrow = Belt_Array.getOrThrow; + let set = Belt_Array.set; let setExn = Belt_Array.setExn; +let setOrThrow = Belt_Array.setOrThrow; + let shuffleInPlace = Belt_Array.shuffleInPlace; let shuffle = Belt_Array.shuffle; @@ -171,8 +175,10 @@ let a = 3; export { get, getExn, + getOrThrow, set, setExn, + setOrThrow, shuffleInPlace, shuffle, reverseInPlace, From 7a6a13548887b6207e3cff40b3661cb06d664d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Sat, 28 Jun 2025 21:46:19 +0100 Subject: [PATCH 02/10] Add Belt.Map.getOrThrow and Belt.MutableMap.getOrThrow --- CHANGELOG.md | 4 +++- analysis/reanalyze/src/ExnLib.ml | 2 +- lib/es6/Belt_Map.js | 7 +++++-- lib/es6/Belt_MapDict.js | 5 ++++- lib/es6/Belt_MutableMap.js | 7 +++++-- lib/es6/Belt_internalAVLtree.js | 4 ++-- lib/js/Belt_Map.js | 7 +++++-- lib/js/Belt_MapDict.js | 5 ++++- lib/js/Belt_MutableMap.js | 7 +++++-- lib/js/Belt_internalAVLtree.js | 4 ++-- runtime/Belt_Map.res | 4 +++- runtime/Belt_Map.resi | 12 +++++++++++- runtime/Belt_MapDict.res | 3 ++- runtime/Belt_MapDict.resi | 3 +++ runtime/Belt_MutableMap.res | 4 +++- runtime/Belt_MutableMap.resi | 2 ++ runtime/Belt_internalAVLtree.res | 4 ++-- runtime/Belt_internalAVLtree.resi | 2 +- 18 files changed, 63 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1947906d56..84f56ff6f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,8 +49,10 @@ - `List.headExn` → `List.headOrThrow` - `Belt.Array.getExn` → `Belt.Array.getOrThrow` - `Belt.Array.setExn` → `Belt.Array.setOrThrow` + - `Belt.Map.getExn` → `Belt.Map.getOrThrow` + - `Belt.MutableMap.getExn` → `Belt.MutableMap.getOrThrow` - 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 + - https://github.com/rescript-lang/rescript/pull/7518, https://github.com/rescript-lang/rescript/pull/7554, https://github.com/rescript-lang/rescript/pull/7581 #### :rocket: New Feature diff --git a/analysis/reanalyze/src/ExnLib.ml b/analysis/reanalyze/src/ExnLib.ml index 710b3d3f61..a88c5ad12f 100644 --- a/analysis/reanalyze/src/ExnLib.ml +++ b/analysis/reanalyze/src/ExnLib.ml @@ -12,7 +12,7 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t = let beltList = [("getExn", [notFound]); ("headExn", [notFound]); ("tailExn", [notFound])] in - let beltMap = [("getExn", [notFound])] in + let beltMap = [("getExn", [notFound]); ("getOrThrow", [notFound])] in let beltMutableMap = beltMap in let beltMutableQueue = [("peekExn", [notFound]); ("popExn", [notFound])] in let beltMutableSet = [("getExn", [notFound])] in diff --git a/lib/es6/Belt_Map.js b/lib/es6/Belt_Map.js index 4018f136e2..4e140f39ec 100644 --- a/lib/es6/Belt_Map.js +++ b/lib/es6/Belt_Map.js @@ -215,8 +215,8 @@ function getWithDefault(map, x, def) { return Belt_MapDict.getWithDefault(map.data, x, def, map.cmp); } -function getExn(map, x) { - return Belt_MapDict.getExn(map.data, x, map.cmp); +function getOrThrow(map, x) { + return Belt_MapDict.getOrThrow(map.data, x, map.cmp); } function has(map, x) { @@ -273,6 +273,8 @@ let everyU = every; let someU = some; +let getExn = getOrThrow; + let updateU = update; let mergeU = merge; @@ -324,6 +326,7 @@ export { getUndefined, getWithDefault, getExn, + getOrThrow, remove, removeMany, set, diff --git a/lib/es6/Belt_MapDict.js b/lib/es6/Belt_MapDict.js index ff9c28eda5..96e5074d70 100644 --- a/lib/es6/Belt_MapDict.js +++ b/lib/es6/Belt_MapDict.js @@ -326,7 +326,9 @@ let getUndefined = Belt_internalAVLtree.getUndefined; let getWithDefault = Belt_internalAVLtree.getWithDefault; -let getExn = Belt_internalAVLtree.getExn; +let getExn = Belt_internalAVLtree.getOrThrow; + +let getOrThrow = Belt_internalAVLtree.getOrThrow; let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal; @@ -386,6 +388,7 @@ export { getUndefined, getWithDefault, getExn, + getOrThrow, checkInvariantInternal, remove, removeMany, diff --git a/lib/es6/Belt_MutableMap.js b/lib/es6/Belt_MutableMap.js index f7bf0c0d85..05d25ff4b6 100644 --- a/lib/es6/Belt_MutableMap.js +++ b/lib/es6/Belt_MutableMap.js @@ -257,8 +257,8 @@ function getWithDefault(m, x, def) { return Belt_internalAVLtree.getWithDefault(m.data, x, def, m.cmp); } -function getExn(m, x) { - return Belt_internalAVLtree.getExn(m.data, x, m.cmp); +function getOrThrow(m, x) { + return Belt_internalAVLtree.getOrThrow(m.data, x, m.cmp); } function has(m, x) { @@ -318,6 +318,8 @@ let everyU = every; let someU = some; +let getExn = getOrThrow; + let updateU = update; let mapU = map; @@ -361,6 +363,7 @@ export { getUndefined, getWithDefault, getExn, + getOrThrow, checkInvariantInternal, remove, removeMany, diff --git a/lib/es6/Belt_internalAVLtree.js b/lib/es6/Belt_internalAVLtree.js index 0745420221..75711d4049 100644 --- a/lib/es6/Belt_internalAVLtree.js +++ b/lib/es6/Belt_internalAVLtree.js @@ -837,7 +837,7 @@ function getUndefined(_n, x, cmp) { }; } -function getExn(_n, x, cmp) { +function getOrThrow(_n, x, cmp) { while (true) { let n = _n; if (n !== undefined) { @@ -1062,7 +1062,7 @@ export { get, getUndefined, getWithDefault, - getExn, + getOrThrow, has, fromArray, updateMutate, diff --git a/lib/js/Belt_Map.js b/lib/js/Belt_Map.js index 8478fd826f..1cbeb9afbe 100644 --- a/lib/js/Belt_Map.js +++ b/lib/js/Belt_Map.js @@ -215,8 +215,8 @@ function getWithDefault(map, x, def) { return Belt_MapDict.getWithDefault(map.data, x, def, map.cmp); } -function getExn(map, x) { - return Belt_MapDict.getExn(map.data, x, map.cmp); +function getOrThrow(map, x) { + return Belt_MapDict.getOrThrow(map.data, x, map.cmp); } function has(map, x) { @@ -273,6 +273,8 @@ let everyU = every; let someU = some; +let getExn = getOrThrow; + let updateU = update; let mergeU = merge; @@ -323,6 +325,7 @@ exports.get = get; exports.getUndefined = getUndefined; exports.getWithDefault = getWithDefault; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.remove = remove; exports.removeMany = removeMany; exports.set = set; diff --git a/lib/js/Belt_MapDict.js b/lib/js/Belt_MapDict.js index 7770cf39da..5670c17c3f 100644 --- a/lib/js/Belt_MapDict.js +++ b/lib/js/Belt_MapDict.js @@ -326,7 +326,9 @@ let getUndefined = Belt_internalAVLtree.getUndefined; let getWithDefault = Belt_internalAVLtree.getWithDefault; -let getExn = Belt_internalAVLtree.getExn; +let getExn = Belt_internalAVLtree.getOrThrow; + +let getOrThrow = Belt_internalAVLtree.getOrThrow; let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal; @@ -385,6 +387,7 @@ exports.get = get; exports.getUndefined = getUndefined; exports.getWithDefault = getWithDefault; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.checkInvariantInternal = checkInvariantInternal; exports.remove = remove; exports.removeMany = removeMany; diff --git a/lib/js/Belt_MutableMap.js b/lib/js/Belt_MutableMap.js index f1e3072c70..ec7301688b 100644 --- a/lib/js/Belt_MutableMap.js +++ b/lib/js/Belt_MutableMap.js @@ -257,8 +257,8 @@ function getWithDefault(m, x, def) { return Belt_internalAVLtree.getWithDefault(m.data, x, def, m.cmp); } -function getExn(m, x) { - return Belt_internalAVLtree.getExn(m.data, x, m.cmp); +function getOrThrow(m, x) { + return Belt_internalAVLtree.getOrThrow(m.data, x, m.cmp); } function has(m, x) { @@ -318,6 +318,8 @@ let everyU = every; let someU = some; +let getExn = getOrThrow; + let updateU = update; let mapU = map; @@ -360,6 +362,7 @@ exports.get = get; exports.getUndefined = getUndefined; exports.getWithDefault = getWithDefault; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.checkInvariantInternal = checkInvariantInternal; exports.remove = remove; exports.removeMany = removeMany; diff --git a/lib/js/Belt_internalAVLtree.js b/lib/js/Belt_internalAVLtree.js index b0b3d3f3e5..ff417e0b6e 100644 --- a/lib/js/Belt_internalAVLtree.js +++ b/lib/js/Belt_internalAVLtree.js @@ -837,7 +837,7 @@ function getUndefined(_n, x, cmp) { }; } -function getExn(_n, x, cmp) { +function getOrThrow(_n, x, cmp) { while (true) { let n = _n; if (n !== undefined) { @@ -1061,7 +1061,7 @@ exports.eq = eq; exports.get = get; exports.getUndefined = getUndefined; exports.getWithDefault = getWithDefault; -exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.has = has; exports.fromArray = fromArray; exports.updateMutate = updateMutate; diff --git a/runtime/Belt_Map.res b/runtime/Belt_Map.res index df8f055eea..697e47efae 100644 --- a/runtime/Belt_Map.res +++ b/runtime/Belt_Map.res @@ -123,7 +123,9 @@ let getUndefined = (map, x) => Dict.getUndefined(~cmp=map.cmp, map.data, x) let getWithDefault = (map, x, def) => Dict.getWithDefault(~cmp=map.cmp, map.data, x, def) -let getExn = (map, x) => Dict.getExn(~cmp=map.cmp, map.data, x) +let getOrThrow = (map, x) => Dict.getOrThrow(~cmp=map.cmp, map.data, x) + +let getExn = getOrThrow let has = (map, x) => Dict.has(~cmp=map.cmp, map.data, x) diff --git a/runtime/Belt_Map.resi b/runtime/Belt_Map.resi index eb5036f11e..c6e56e27f8 100644 --- a/runtime/Belt_Map.resi +++ b/runtime/Belt_Map.resi @@ -379,12 +379,22 @@ let getWithDefault: (t<'k, 'v, 'id>, 'k, 'v) => 'v /** `getExn(s, k)` -See `Belt.Map.getExn` +See `Belt.Map.get` raise when `k` not exist */ +@deprecated("Use `getOrThrow` instead") let getExn: (t<'k, 'v, 'id>, 'k) => 'v +/** +`getOrThrow(s, k)` + +See `Belt.Map.get` + +raise when `k` not exist +*/ +let getOrThrow: (t<'k, 'v, 'id>, 'k) => 'v + /* ************************************************************************** */ /** diff --git a/runtime/Belt_MapDict.res b/runtime/Belt_MapDict.res index 1472d96414..0190b4b311 100644 --- a/runtime/Belt_MapDict.res +++ b/runtime/Belt_MapDict.res @@ -59,7 +59,8 @@ let maxUndefined = N.maxUndefined let get = N.get let getUndefined = N.getUndefined let getWithDefault = N.getWithDefault -let getExn = N.getExn +let getOrThrow = N.getOrThrow +let getExn = getOrThrow let mapWithKey = N.mapWithKey diff --git a/runtime/Belt_MapDict.resi b/runtime/Belt_MapDict.resi index 0e41b0a743..a829bb0526 100644 --- a/runtime/Belt_MapDict.resi +++ b/runtime/Belt_MapDict.resi @@ -153,8 +153,11 @@ let getUndefined: (t<'k, 'a, 'id>, 'k, ~cmp: cmp<'k, 'id>) => Js.undefined<'a> let getWithDefault: (t<'k, 'a, 'id>, 'k, 'a, ~cmp: cmp<'k, 'id>) => 'a +@deprecated("Use `getOrThrow` instead") let getExn: (t<'k, 'a, 'id>, 'k, ~cmp: cmp<'k, 'id>) => 'a +let getOrThrow: (t<'k, 'a, 'id>, 'k, ~cmp: cmp<'k, 'id>) => 'a + let checkInvariantInternal: t<_> => unit /** diff --git a/runtime/Belt_MutableMap.res b/runtime/Belt_MutableMap.res index b27c6792c4..2b10a40e7d 100644 --- a/runtime/Belt_MutableMap.res +++ b/runtime/Belt_MutableMap.res @@ -190,7 +190,9 @@ let getUndefined = (m, x) => N.getUndefined(~cmp=m.cmp, m.data, x) let getWithDefault = (m, x, def) => N.getWithDefault(~cmp=m.cmp, m.data, x, def) -let getExn = (m, x) => N.getExn(~cmp=m.cmp, m.data, x) +let getOrThrow = (m, x) => N.getOrThrow(~cmp=m.cmp, m.data, x) + +let getExn = getOrThrow let has = (m, x) => N.has(~cmp=m.cmp, m.data, x) diff --git a/runtime/Belt_MutableMap.resi b/runtime/Belt_MutableMap.resi index 5a36174829..c23aeda296 100644 --- a/runtime/Belt_MutableMap.resi +++ b/runtime/Belt_MutableMap.resi @@ -120,7 +120,9 @@ let maxUndefined: t<'k, 'a, _> => Js.undefined<('k, 'a)> let get: (t<'k, 'a, 'id>, 'k) => option<'a> let getUndefined: (t<'k, 'a, 'id>, 'k) => Js.undefined<'a> let getWithDefault: (t<'k, 'a, 'id>, 'k, 'a) => 'a +@deprecated("Use `getOrThrow` instead") let getExn: (t<'k, 'a, 'id>, 'k) => 'a +let getOrThrow: (t<'k, 'a, 'id>, 'k) => 'a /** Raise when invariant is not held. */ let checkInvariantInternal: t<_> => unit diff --git a/runtime/Belt_internalAVLtree.res b/runtime/Belt_internalAVLtree.res index cdb0dc67f0..43455a3efa 100644 --- a/runtime/Belt_internalAVLtree.res +++ b/runtime/Belt_internalAVLtree.res @@ -711,7 +711,7 @@ let rec getUndefined = (n, x, ~cmp) => } } -let rec getExn = (n, x, ~cmp) => +let rec getOrThrow = (n, x, ~cmp) => switch n { | None => throw(Not_found) | Some(n) /* Node(l, v, d, r, _) */ => @@ -720,7 +720,7 @@ let rec getExn = (n, x, ~cmp) => if c == 0 { n.value } else { - getExn( + getOrThrow( ~cmp, if c < 0 { n.left diff --git a/runtime/Belt_internalAVLtree.resi b/runtime/Belt_internalAVLtree.resi index 31e76254bb..fe1889a79f 100644 --- a/runtime/Belt_internalAVLtree.resi +++ b/runtime/Belt_internalAVLtree.resi @@ -114,7 +114,7 @@ let get: (t<'a, 'b>, 'a, ~cmp: cmp<'a, _>) => option<'b> let getUndefined: (t<'a, 'b>, 'a, ~cmp: cmp<'a, _>) => Js.undefined<'b> let getWithDefault: (t<'a, 'b>, 'a, 'b, ~cmp: cmp<'a, _>) => 'b -let getExn: (t<'a, 'b>, 'a, ~cmp: cmp<'a, _>) => 'b +let getOrThrow: (t<'a, 'b>, 'a, ~cmp: cmp<'a, _>) => 'b let has: (t<'a, 'b>, 'a, ~cmp: cmp<'a, _>) => bool From 247d7bf1c01c2289efbd38967f5761a1a8736af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Sun, 29 Jun 2025 15:36:23 +0100 Subject: [PATCH 03/10] Add Belt.Set.getOrThrow and Belt.MutableSet.getOrThrow --- CHANGELOG.md | 2 ++ analysis/reanalyze/src/ExnLib.ml | 4 ++-- lib/es6/Belt_MutableSet.js | 7 +++++-- lib/es6/Belt_SetDict.js | 5 ++++- lib/es6/Belt_internalAVLset.js | 4 ++-- lib/js/Belt_MutableSet.js | 7 +++++-- lib/js/Belt_SetDict.js | 5 ++++- lib/js/Belt_internalAVLset.js | 4 ++-- runtime/Belt_MutableSet.res | 4 +++- runtime/Belt_MutableSet.resi | 6 ++++++ runtime/Belt_Set.res | 4 +++- runtime/Belt_Set.resi | 10 ++++++++-- runtime/Belt_SetDict.res | 3 ++- runtime/Belt_SetDict.resi | 6 ++++++ runtime/Belt_internalAVLset.res | 4 ++-- runtime/Belt_internalAVLset.resi | 2 +- 16 files changed, 57 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84f56ff6f3..ec64599099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,8 @@ - `Belt.Array.setExn` → `Belt.Array.setOrThrow` - `Belt.Map.getExn` → `Belt.Map.getOrThrow` - `Belt.MutableMap.getExn` → `Belt.MutableMap.getOrThrow` + - `Belt.Set.getExn` → `Belt.Set.getOrThrow` + - `Belt.MutableSet.getExn` → `Belt.MutableSet.getOrThrow` - 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, https://github.com/rescript-lang/rescript/pull/7581 diff --git a/analysis/reanalyze/src/ExnLib.ml b/analysis/reanalyze/src/ExnLib.ml index a88c5ad12f..c0c1dc0394 100644 --- a/analysis/reanalyze/src/ExnLib.ml +++ b/analysis/reanalyze/src/ExnLib.ml @@ -15,10 +15,10 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t = let beltMap = [("getExn", [notFound]); ("getOrThrow", [notFound])] in let beltMutableMap = beltMap in let beltMutableQueue = [("peekExn", [notFound]); ("popExn", [notFound])] in - let beltMutableSet = [("getExn", [notFound])] in + let beltSet = [("getExn", [notFound]); ("getOrThrow", [notFound])] in + let beltMutableSet = beltSet in let beltOption = [("getExn", [notFound])] in let beltResult = [("getExn", [notFound])] in - let beltSet = [("getExn", [notFound])] in let bsJson = (* bs-json *) [ diff --git a/lib/es6/Belt_MutableSet.js b/lib/es6/Belt_MutableSet.js index 3f03b12e70..c69e12229a 100644 --- a/lib/es6/Belt_MutableSet.js +++ b/lib/es6/Belt_MutableSet.js @@ -276,8 +276,8 @@ function getUndefined(d, x) { return Belt_internalAVLset.getUndefined(d.data, x, d.cmp); } -function getExn(d, x) { - return Belt_internalAVLset.getExn(d.data, x, d.cmp); +function getOrThrow(d, x) { + return Belt_internalAVLset.getOrThrow(d.data, x, d.cmp); } function split(d, key) { @@ -477,6 +477,8 @@ let keepU = keep; let partitionU = partition; +let getExn = getOrThrow; + export { Int, $$String, @@ -520,6 +522,7 @@ export { get, getUndefined, getExn, + getOrThrow, split, checkInvariantInternal, } diff --git a/lib/es6/Belt_SetDict.js b/lib/es6/Belt_SetDict.js index 66471e9850..89db93aea9 100644 --- a/lib/es6/Belt_SetDict.js +++ b/lib/es6/Belt_SetDict.js @@ -314,7 +314,9 @@ let get = Belt_internalAVLset.get; let getUndefined = Belt_internalAVLset.getUndefined; -let getExn = Belt_internalAVLset.getExn; +let getExn = Belt_internalAVLset.getOrThrow; + +let getOrThrow = Belt_internalAVLset.getOrThrow; let checkInvariantInternal = Belt_internalAVLset.checkInvariantInternal; @@ -356,6 +358,7 @@ export { get, getUndefined, getExn, + getOrThrow, split, checkInvariantInternal, } diff --git a/lib/es6/Belt_internalAVLset.js b/lib/es6/Belt_internalAVLset.js index c96f412eb4..a94e510cef 100644 --- a/lib/es6/Belt_internalAVLset.js +++ b/lib/es6/Belt_internalAVLset.js @@ -688,7 +688,7 @@ function getUndefined(_n, x, cmp) { }; } -function getExn(_n, x, cmp) { +function getOrThrow(_n, x, cmp) { while (true) { let n = _n; if (n !== undefined) { @@ -877,7 +877,7 @@ export { subset, get, getUndefined, - getExn, + getOrThrow, fromArray, addMutate, balMutate, diff --git a/lib/js/Belt_MutableSet.js b/lib/js/Belt_MutableSet.js index 278f08d1f0..610820feab 100644 --- a/lib/js/Belt_MutableSet.js +++ b/lib/js/Belt_MutableSet.js @@ -276,8 +276,8 @@ function getUndefined(d, x) { return Belt_internalAVLset.getUndefined(d.data, x, d.cmp); } -function getExn(d, x) { - return Belt_internalAVLset.getExn(d.data, x, d.cmp); +function getOrThrow(d, x) { + return Belt_internalAVLset.getOrThrow(d.data, x, d.cmp); } function split(d, key) { @@ -477,6 +477,8 @@ let keepU = keep; let partitionU = partition; +let getExn = getOrThrow; + exports.Int = Int; exports.$$String = $$String; exports.make = make; @@ -519,6 +521,7 @@ exports.maxUndefined = maxUndefined; exports.get = get; exports.getUndefined = getUndefined; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.split = split; exports.checkInvariantInternal = checkInvariantInternal; /* No side effect */ diff --git a/lib/js/Belt_SetDict.js b/lib/js/Belt_SetDict.js index d80140120e..cdb20ddfba 100644 --- a/lib/js/Belt_SetDict.js +++ b/lib/js/Belt_SetDict.js @@ -314,7 +314,9 @@ let get = Belt_internalAVLset.get; let getUndefined = Belt_internalAVLset.getUndefined; -let getExn = Belt_internalAVLset.getExn; +let getExn = Belt_internalAVLset.getOrThrow; + +let getOrThrow = Belt_internalAVLset.getOrThrow; let checkInvariantInternal = Belt_internalAVLset.checkInvariantInternal; @@ -355,6 +357,7 @@ exports.maxUndefined = maxUndefined; exports.get = get; exports.getUndefined = getUndefined; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.split = split; exports.checkInvariantInternal = checkInvariantInternal; /* No side effect */ diff --git a/lib/js/Belt_internalAVLset.js b/lib/js/Belt_internalAVLset.js index ccffdcd473..0c97faaf22 100644 --- a/lib/js/Belt_internalAVLset.js +++ b/lib/js/Belt_internalAVLset.js @@ -688,7 +688,7 @@ function getUndefined(_n, x, cmp) { }; } -function getExn(_n, x, cmp) { +function getOrThrow(_n, x, cmp) { while (true) { let n = _n; if (n !== undefined) { @@ -876,7 +876,7 @@ exports.eq = eq; exports.subset = subset; exports.get = get; exports.getUndefined = getUndefined; -exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.fromArray = fromArray; exports.addMutate = addMutate; exports.balMutate = balMutate; diff --git a/runtime/Belt_MutableSet.res b/runtime/Belt_MutableSet.res index bc553ea368..5b1af51f9c 100644 --- a/runtime/Belt_MutableSet.res +++ b/runtime/Belt_MutableSet.res @@ -235,7 +235,9 @@ let get = (d, x) => N.get(~cmp=d.cmp, d.data, x) let getUndefined = (d, x) => N.getUndefined(~cmp=d.cmp, d.data, x) -let getExn = (d, x) => N.getExn(~cmp=d.cmp, d.data, x) +let getOrThrow = (d, x) => N.getOrThrow(~cmp=d.cmp, d.data, x) + +let getExn = getOrThrow let split = (d, key) => { let arr = N.toArray(d.data) diff --git a/runtime/Belt_MutableSet.resi b/runtime/Belt_MutableSet.resi index 647369af20..5ea7d51431 100644 --- a/runtime/Belt_MutableSet.resi +++ b/runtime/Belt_MutableSet.resi @@ -637,8 +637,14 @@ let getUndefined: (t<'value, 'id>, 'value) => Js.undefined<'value> /** Same as `Belt.MutableSet.get` but raise when element does not exist. */ +@deprecated("Use `getOrThrow` instead") let getExn: (t<'value, 'id>, 'value) => 'value +/** +Same as `Belt.MutableSet.get` but raise when element does not exist. +*/ +let getOrThrow: (t<'value, 'id>, 'value) => 'value + /** Returns a tuple `((smaller, larger), present)`, `present` is true when element exist in set. diff --git a/runtime/Belt_Set.res b/runtime/Belt_Set.res index 70e2dd9383..5e5b87d2d4 100644 --- a/runtime/Belt_Set.res +++ b/runtime/Belt_Set.res @@ -130,7 +130,9 @@ let get = (m, e) => Dict.get(~cmp=m.cmp, m.data, e) let getUndefined = (m, e) => Dict.getUndefined(~cmp=m.cmp, m.data, e) -let getExn = (m, e) => Dict.getExn(~cmp=m.cmp, m.data, e) +let getOrThrow = (m, e) => Dict.getOrThrow(~cmp=m.cmp, m.data, e) + +let getExn = getOrThrow let has = (m, e) => Dict.has(~cmp=m.cmp, m.data, e) diff --git a/runtime/Belt_Set.resi b/runtime/Belt_Set.resi index b838a78991..5ca7ea5568 100644 --- a/runtime/Belt_Set.resi +++ b/runtime/Belt_Set.resi @@ -60,7 +60,7 @@ module IntCmp = ``` */ -/** +/** Specialized when value type is `int`, more efficient than the generic type, its compare behavior is fixed using the built-in comparison */ @@ -72,7 +72,7 @@ its compare behavior is fixed using the built-in comparison */ module String = Belt_SetString -/** +/** This module separates identity from data, it is a bit more verbose but slightly more efficient due to the fact that there is no need to pack identity and data back after each operation @@ -697,8 +697,14 @@ let getUndefined: (t<'value, 'id>, 'value) => Js.undefined<'value> /** Same as [get](#get) but raise when element does not exist. */ +@deprecated("Use `getOrThrow` instead") let getExn: (t<'value, 'id>, 'value) => 'value +/** +Same as [get](#get) but raise when element does not exist. +*/ +let getOrThrow: (t<'value, 'id>, 'value) => 'value + /** Returns a tuple `((smaller, larger), present)`, `present` is true when element exist in set. diff --git a/runtime/Belt_SetDict.res b/runtime/Belt_SetDict.res index 7758446217..f272763a76 100644 --- a/runtime/Belt_SetDict.res +++ b/runtime/Belt_SetDict.res @@ -251,7 +251,8 @@ let maximum = N.maximum let maxUndefined = N.maxUndefined let minUndefined = N.minUndefined let get = N.get -let getExn = N.getExn +let getOrThrow = N.getOrThrow +let getExn = getOrThrow let getUndefined = N.getUndefined let fromSortedArrayUnsafe = N.fromSortedArrayUnsafe diff --git a/runtime/Belt_SetDict.resi b/runtime/Belt_SetDict.resi index 66be267a7b..f557d212c3 100644 --- a/runtime/Belt_SetDict.resi +++ b/runtime/Belt_SetDict.resi @@ -608,8 +608,14 @@ let getUndefined: (t<'value, 'id>, 'value, ~cmp: cmp<'value, 'id>) => Js.undefin /** Same as [get](#get) but raise when element does not exist. */ +@deprecated("Use `getOrThrow` instead") let getExn: (t<'value, 'id>, 'value, ~cmp: cmp<'value, 'id>) => 'value +/** +Same as [get](#get) but raise when element does not exist. +*/ +let getOrThrow: (t<'value, 'id>, 'value, ~cmp: cmp<'value, 'id>) => 'value + /** Returns a tuple `((smaller, larger), present)`, `present` is true when element exist in set. diff --git a/runtime/Belt_internalAVLset.res b/runtime/Belt_internalAVLset.res index 46954fd095..b823ee585d 100644 --- a/runtime/Belt_internalAVLset.res +++ b/runtime/Belt_internalAVLset.res @@ -588,7 +588,7 @@ let rec getUndefined = (n: t<_>, x, ~cmp) => } } -let rec getExn = (n: t<_>, x, ~cmp) => +let rec getOrThrow = (n: t<_>, x, ~cmp) => switch n { | None => throw(Not_found) | Some(t) /* Node(l, v, r, _) */ => @@ -597,7 +597,7 @@ let rec getExn = (n: t<_>, x, ~cmp) => if c == 0 { v } else { - getExn( + getOrThrow( ~cmp, if c < 0 { t.left diff --git a/runtime/Belt_internalAVLset.resi b/runtime/Belt_internalAVLset.resi index c4be58b004..d66a8a4488 100644 --- a/runtime/Belt_internalAVLset.resi +++ b/runtime/Belt_internalAVLset.resi @@ -95,7 +95,7 @@ let eq: (t<'a>, t<'a>, ~cmp: cmp<'a, 'b>) => bool let subset: (t<'a>, t<'a>, ~cmp: cmp<'a, 'b>) => bool let get: (t<'a>, 'a, ~cmp: cmp<'a, 'b>) => option<'a> let getUndefined: (t<'a>, 'a, ~cmp: cmp<'a, 'b>) => Js.undefined<'a> -let getExn: (t<'a>, 'a, ~cmp: cmp<'a, 'b>) => 'a +let getOrThrow: (t<'a>, 'a, ~cmp: cmp<'a, 'b>) => 'a let fromArray: (array<'a>, ~cmp: cmp<'a, 'b>) => t<'a> From f7073fcbd84fad1e7c046f32577f7bbccd262729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Sun, 29 Jun 2025 15:36:37 +0100 Subject: [PATCH 04/10] Exclude rewatch from biome checks --- biome.json | 1 + 1 file changed, 1 insertion(+) diff --git a/biome.json b/biome.json index 190824e65b..1e99f64fb9 100644 --- a/biome.json +++ b/biome.json @@ -62,6 +62,7 @@ "tests/tests/**/src/**", "tests/tools_tests/**/src/**", "analysis/examples/**/src/**", + "rewatch/**", "lib/es6/**", "lib/js/**", "ninja/**", From 453ac89d7baf204033174daf86bf775dad51f412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Sun, 29 Jun 2025 15:41:09 +0100 Subject: [PATCH 05/10] Add Belt.List.getOrThrow, headOrThrow and tailOrThrow --- CHANGELOG.md | 3 ++ analysis/reanalyze/src/ExnLib.ml | 9 ++++- runtime/Belt_List.res | 12 ++++-- runtime/Belt_List.resi | 56 ++++++++++++++++++++++++++++ tests/tests/src/exception_alias.mjs | 3 ++ tests/tests/src/test_ari.mjs | 9 +++++ tests/tests/src/test_include.mjs | 9 +++++ tests/tests/src/test_pervasive.mjs | 3 ++ tests/tests/src/test_pervasives3.mjs | 3 ++ 9 files changed, 103 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec64599099..8d3a949282 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,9 @@ - `Belt.MutableMap.getExn` → `Belt.MutableMap.getOrThrow` - `Belt.Set.getExn` → `Belt.Set.getOrThrow` - `Belt.MutableSet.getExn` → `Belt.MutableSet.getOrThrow` + - `Belt.List.getExn` → `Belt.List.getOrThrow` + - `Belt.List.tailExn` → `Belt.List.tailOrThrow` + - `Belt.List.headExn` → `Belt.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, https://github.com/rescript-lang/rescript/pull/7581 diff --git a/analysis/reanalyze/src/ExnLib.ml b/analysis/reanalyze/src/ExnLib.ml index c0c1dc0394..8b69222023 100644 --- a/analysis/reanalyze/src/ExnLib.ml +++ b/analysis/reanalyze/src/ExnLib.ml @@ -10,7 +10,14 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t = ] in let beltList = - [("getExn", [notFound]); ("headExn", [notFound]); ("tailExn", [notFound])] + [ + ("getExn", [notFound]); + ("getOrThrow", [notFound]); + ("headExn", [notFound]); + ("headOrThrow", [notFound]); + ("tailExn", [notFound]); + ("tailOrThrow", [notFound]); + ] in let beltMap = [("getExn", [notFound]); ("getOrThrow", [notFound])] in let beltMutableMap = beltMap in diff --git a/runtime/Belt_List.res b/runtime/Belt_List.res index b282a596ac..1b657ae906 100644 --- a/runtime/Belt_List.res +++ b/runtime/Belt_List.res @@ -86,24 +86,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` */ @@ -136,13 +140,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{} => () diff --git a/runtime/Belt_List.resi b/runtime/Belt_List.resi index a615ce1b05..c0c5b875b8 100644 --- a/runtime/Belt_List.resi +++ b/runtime/Belt_List.resi @@ -77,8 +77,26 @@ switch Belt.List.headExn(list{}) { // Raises an Error } ``` */ +@deprecated("Use `headOrThrow` instead") let headExn: t<'a> => 'a +/** +Same as `Belt.List.head` but raises an exception if `someList` is empty. Use +with care. + +## Examples + +```rescript +Belt.List.headOrThrow(list{1, 2, 3})->assertEqual(1) + +switch Belt.List.headOrThrow(list{}) { // Raises an Error +| exception _ => assert(true) +| _ => assert(false) +} +``` +*/ +let headOrThrow: t<'a> => 'a + /** Returns `None` if `someList` is empty, otherwise it returns `Some(tail)` where `tail` is everything except the first element of `someList`. @@ -108,8 +126,26 @@ switch Belt.List.tailExn(list{}) { // Raises an Error } ``` */ +@deprecated("Use `tailOrThrow` instead") let tailExn: t<'a> => t<'a> +/** +Same as `Belt.List.tail` but raises an exception if `someList` is empty. Use +with care. + +## Examples + +```rescript +Belt.List.tailOrThrow(list{1, 2, 3})->assertEqual(list{2, 3}) + +switch Belt.List.tailOrThrow(list{}) { // Raises an Error +| exception _ => assert(true) +| _ => assert(false) +} +``` +*/ +let tailOrThrow: t<'a> => t<'a> + /** Adds `value` to the beginning of `someList`. @@ -156,8 +192,28 @@ switch abc->Belt.List.getExn(4) { // Raises an Error } ``` */ +@deprecated("Use `getOrThrow` instead") let getExn: (t<'a>, int) => 'a +/** +Same as `Belt.List.get` but raises an exception if `index` is larger than the +length. Use with care. + +## Examples + +```rescript +let abc = list{"A", "B", "C"} + +abc->Belt.List.getOrThrow(1)->assertEqual("B") + +switch abc->Belt.List.getOrThrow(4) { // Raises an Error +| exception _ => assert(true) +| _ => assert(false) +} +``` +*/ +let getOrThrow: (t<'a>, int) => 'a + /** Returns a list of length `numItems` with each element filled with value `v`. Returns an empty list if `numItems` is negative. diff --git a/tests/tests/src/exception_alias.mjs b/tests/tests/src/exception_alias.mjs index 2b2cac959e..6f2e89d465 100644 --- a/tests/tests/src/exception_alias.mjs +++ b/tests/tests/src/exception_alias.mjs @@ -18,11 +18,14 @@ let List = { size: Belt_List.size, head: Belt_List.head, headExn: Belt_List.headExn, + headOrThrow: Belt_List.headOrThrow, tail: Belt_List.tail, tailExn: Belt_List.tailExn, + tailOrThrow: Belt_List.tailOrThrow, add: Belt_List.add, get: Belt_List.get, getExn: Belt_List.getExn, + getOrThrow: Belt_List.getOrThrow, make: Belt_List.make, makeByU: Belt_List.makeByU, makeBy: Belt_List.makeBy, diff --git a/tests/tests/src/test_ari.mjs b/tests/tests/src/test_ari.mjs index a36e53d1df..a969b30718 100644 --- a/tests/tests/src/test_ari.mjs +++ b/tests/tests/src/test_ari.mjs @@ -49,16 +49,22 @@ let head = Belt_List.head; let headExn = Belt_List.headExn; +let headOrThrow = Belt_List.headOrThrow; + let tail = Belt_List.tail; let tailExn = Belt_List.tailExn; +let tailOrThrow = Belt_List.tailOrThrow; + let add = Belt_List.add; let get = Belt_List.get; let getExn = Belt_List.getExn; +let getOrThrow = Belt_List.getOrThrow; + let make = Belt_List.make; let makeByU = Belt_List.makeByU; @@ -230,11 +236,14 @@ export { size, head, headExn, + headOrThrow, tail, tailExn, + tailOrThrow, add, get, getExn, + getOrThrow, make, makeByU, makeBy, diff --git a/tests/tests/src/test_include.mjs b/tests/tests/src/test_include.mjs index 453e8f2a28..48184caff3 100644 --- a/tests/tests/src/test_include.mjs +++ b/tests/tests/src/test_include.mjs @@ -39,16 +39,22 @@ let head = Belt_List.head; let headExn = Belt_List.headExn; +let headOrThrow = Belt_List.headOrThrow; + let tail = Belt_List.tail; let tailExn = Belt_List.tailExn; +let tailOrThrow = Belt_List.tailOrThrow; + let add = Belt_List.add; let get = Belt_List.get; let getExn = Belt_List.getExn; +let getOrThrow = Belt_List.getOrThrow; + let make = Belt_List.make; let makeByU = Belt_List.makeByU; @@ -223,11 +229,14 @@ export { size, head, headExn, + headOrThrow, tail, tailExn, + tailOrThrow, add, get, getExn, + getOrThrow, make, makeByU, makeBy, diff --git a/tests/tests/src/test_pervasive.mjs b/tests/tests/src/test_pervasive.mjs index 7d11ae6586..a38996affb 100644 --- a/tests/tests/src/test_pervasive.mjs +++ b/tests/tests/src/test_pervasive.mjs @@ -8,11 +8,14 @@ let Pervasives$1 = { size: Belt_List.size, head: Belt_List.head, headExn: Belt_List.headExn, + headOrThrow: Belt_List.headOrThrow, tail: Belt_List.tail, tailExn: Belt_List.tailExn, + tailOrThrow: Belt_List.tailOrThrow, add: Belt_List.add, get: Belt_List.get, getExn: Belt_List.getExn, + getOrThrow: Belt_List.getOrThrow, make: Belt_List.make, makeByU: Belt_List.makeByU, makeBy: Belt_List.makeBy, diff --git a/tests/tests/src/test_pervasives3.mjs b/tests/tests/src/test_pervasives3.mjs index 8bf1d03542..39061f78f0 100644 --- a/tests/tests/src/test_pervasives3.mjs +++ b/tests/tests/src/test_pervasives3.mjs @@ -26,11 +26,14 @@ let Pervasives$1 = { size: Belt_List.size, head: Belt_List.head, headExn: Belt_List.headExn, + headOrThrow: Belt_List.headOrThrow, tail: Belt_List.tail, tailExn: Belt_List.tailExn, + tailOrThrow: Belt_List.tailOrThrow, add: Belt_List.add, get: Belt_List.get, getExn: Belt_List.getExn, + getOrThrow: Belt_List.getOrThrow, make: Belt_List.make, makeByU: Belt_List.makeByU, makeBy: Belt_List.makeBy, From 837ff78de25cd75137024f34042e2ed14218457f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Sun, 29 Jun 2025 15:48:21 +0100 Subject: [PATCH 06/10] Add Belt.MutableQueue.peekOrThrow and popOrThrow --- CHANGELOG.md | 2 ++ analysis/reanalyze/src/ExnLib.ml | 9 ++++++++- runtime/Belt_MutableQueue.res | 8 ++++++-- runtime/Belt_MutableQueue.resi | 14 +++++++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d3a949282..edb4e4a927 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,8 @@ - `Belt.List.getExn` → `Belt.List.getOrThrow` - `Belt.List.tailExn` → `Belt.List.tailOrThrow` - `Belt.List.headExn` → `Belt.List.headOrThrow` + - `Belt.MutableQueue.peekExn` → `Belt.MutableQueue.peekOrThrow` + - `Belt.MutableQueue.popExn` → `Belt.MutableQueue.popOrThrow` - 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, https://github.com/rescript-lang/rescript/pull/7581 diff --git a/analysis/reanalyze/src/ExnLib.ml b/analysis/reanalyze/src/ExnLib.ml index 8b69222023..5e33e2db32 100644 --- a/analysis/reanalyze/src/ExnLib.ml +++ b/analysis/reanalyze/src/ExnLib.ml @@ -21,7 +21,14 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t = in let beltMap = [("getExn", [notFound]); ("getOrThrow", [notFound])] in let beltMutableMap = beltMap in - let beltMutableQueue = [("peekExn", [notFound]); ("popExn", [notFound])] in + let beltMutableQueue = + [ + ("peekExn", [notFound]); + ("peekOrThrow", [notFound]); + ("popExn", [notFound]); + ("popOrThrow", [notFound]); + ] + in let beltSet = [("getExn", [notFound]); ("getOrThrow", [notFound])] in let beltMutableSet = beltSet in let beltOption = [("getExn", [notFound])] in diff --git a/runtime/Belt_MutableQueue.res b/runtime/Belt_MutableQueue.res index 40d39c319d..61b60ae461 100644 --- a/runtime/Belt_MutableQueue.res +++ b/runtime/Belt_MutableQueue.res @@ -70,12 +70,14 @@ let peekUndefined = q => | Some(v) => Js.Undefined.return(v.content) } -let peekExn = q => +let peekOrThrow = q => switch q.first { | None => throw(Not_found) | Some(v) => v.content } +let peekExn = peekOrThrow + let pop = q => switch q.first { | None => None @@ -92,7 +94,7 @@ let pop = q => } } -let popExn = q => +let popOrThrow = q => /* TO fix */ switch q.first { | None => throw(Not_found) @@ -109,6 +111,8 @@ let popExn = q => } } +let popExn = popOrThrow + let popUndefined = q => switch q.first { | None => Js.undefined diff --git a/runtime/Belt_MutableQueue.resi b/runtime/Belt_MutableQueue.resi index ebecc05146..6177510c3e 100644 --- a/runtime/Belt_MutableQueue.resi +++ b/runtime/Belt_MutableQueue.resi @@ -59,10 +59,16 @@ let peek: t<'a> => option<'a> let peekUndefined: t<'a> => Js.undefined<'a> /** -raise an exception if `q` is empty +`peekExn(q)` raises an exception if `q` is empty. */ +@deprecated("Use `peekOrThrow` instead") let peekExn: t<'a> => 'a +/** +`peekOrThrow(q)` raises an exception if `q` is empty. +*/ +let peekOrThrow: t<'a> => 'a + /** `pop(q)` removes and returns the first element in queue `q`. */ @@ -77,8 +83,14 @@ let popUndefined: t<'a> => Js.undefined<'a> /** `popExn(q)` raise an exception if q is empty. */ +@deprecated("Use `popOrThrow` instead") let popExn: t<'a> => 'a +/** +`popOrThrow(q)` raise an exception if q is empty. +*/ +let popOrThrow: t<'a> => 'a + /** `copy(q)` returns a fresh queue. */ From 01e6caca6103762cf76e38273323e5e934ae515d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Sun, 29 Jun 2025 16:05:34 +0100 Subject: [PATCH 07/10] Add Belt.Option.getOrThrow --- CHANGELOG.md | 1 + analysis/reanalyze/src/ExnLib.ml | 2 +- runtime/Belt_Option.res | 4 +++- runtime/Belt_Option.resi | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edb4e4a927..c688d585d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ - `Belt.List.headExn` → `Belt.List.headOrThrow` - `Belt.MutableQueue.peekExn` → `Belt.MutableQueue.peekOrThrow` - `Belt.MutableQueue.popExn` → `Belt.MutableQueue.popOrThrow` + - `Belt.Option.getExn` → `Belt.Option.getOrThrow` - 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, https://github.com/rescript-lang/rescript/pull/7581 diff --git a/analysis/reanalyze/src/ExnLib.ml b/analysis/reanalyze/src/ExnLib.ml index 5e33e2db32..8b31834bc9 100644 --- a/analysis/reanalyze/src/ExnLib.ml +++ b/analysis/reanalyze/src/ExnLib.ml @@ -31,7 +31,7 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t = in let beltSet = [("getExn", [notFound]); ("getOrThrow", [notFound])] in let beltMutableSet = beltSet in - let beltOption = [("getExn", [notFound])] in + let beltOption = [("getExn", [notFound]); ("getOrThrow", [notFound])] in let beltResult = [("getExn", [notFound])] in let bsJson = (* bs-json *) diff --git a/runtime/Belt_Option.res b/runtime/Belt_Option.res index cd2f7e0596..618df9dfad 100644 --- a/runtime/Belt_Option.res +++ b/runtime/Belt_Option.res @@ -34,12 +34,14 @@ let forEach = (opt, f) => | None => () } -let getExn = x => +let getOrThrow = x => switch x { | Some(x) => x | None => throw(Not_found) } +let getExn = getOrThrow + external getUnsafe: option<'a> => 'a = "%identity" let mapWithDefault = (opt, default, f) => diff --git a/runtime/Belt_Option.resi b/runtime/Belt_Option.resi index 8bae85a5ca..295631edfc 100644 --- a/runtime/Belt_Option.resi +++ b/runtime/Belt_Option.resi @@ -89,8 +89,27 @@ switch Belt.Option.getExn(None) { // Raises an exception } ``` */ +@deprecated("Use `getOrThrow` instead") let getExn: option<'a> => 'a +/** +Raises an Error in case `None` is provided. Use with care. + +## Examples + +```rescript +Some(3) +->Belt.Option.getOrThrow +->assertEqual(3) + +switch Belt.Option.getOrThrow(None) { // Raises an exception +| exception _ => assert(true) +| _ => assert(false) +} +``` +*/ +let getOrThrow: option<'a> => 'a + /** `getUnsafe(x)` returns `x` From ae3ce161f55537777ed0dd460c9ae43087bad9fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Sun, 29 Jun 2025 16:07:09 +0100 Subject: [PATCH 08/10] Add Belt.Result.getOrThrow --- CHANGELOG.md | 1 + analysis/reanalyze/src/ExnLib.ml | 2 +- runtime/Belt_Result.res | 4 +++- runtime/Belt_Result.resi | 20 ++++++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c688d585d0..eec48a5160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ - `Belt.MutableQueue.peekExn` → `Belt.MutableQueue.peekOrThrow` - `Belt.MutableQueue.popExn` → `Belt.MutableQueue.popOrThrow` - `Belt.Option.getExn` → `Belt.Option.getOrThrow` + - `Belt.Result.getExn` → `Belt.Result.getOrThrow` - 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, https://github.com/rescript-lang/rescript/pull/7581 diff --git a/analysis/reanalyze/src/ExnLib.ml b/analysis/reanalyze/src/ExnLib.ml index 8b31834bc9..3b9f2602ff 100644 --- a/analysis/reanalyze/src/ExnLib.ml +++ b/analysis/reanalyze/src/ExnLib.ml @@ -32,7 +32,7 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t = let beltSet = [("getExn", [notFound]); ("getOrThrow", [notFound])] in let beltMutableSet = beltSet in let beltOption = [("getExn", [notFound]); ("getOrThrow", [notFound])] in - let beltResult = [("getExn", [notFound])] in + let beltResult = [("getExn", [notFound]); ("getOrThrow", [notFound])] in let bsJson = (* bs-json *) [ diff --git a/runtime/Belt_Result.res b/runtime/Belt_Result.res index d85948a96d..d2512b2102 100644 --- a/runtime/Belt_Result.res +++ b/runtime/Belt_Result.res @@ -26,12 +26,14 @@ type t<'a, 'b> = result<'a, 'b> = | Ok('a) | Error('b) -let getExn = x => +let getOrThrow = x => switch x { | Ok(x) => x | Error(_) => throw(Not_found) } +let getExn = getOrThrow + let mapWithDefault = (opt, default, f) => switch opt { | Ok(x) => f(x) diff --git a/runtime/Belt_Result.resi b/runtime/Belt_Result.resi index cdccf11312..936fb895b2 100644 --- a/runtime/Belt_Result.resi +++ b/runtime/Belt_Result.resi @@ -50,8 +50,28 @@ switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { // raise a except } ``` */ +@deprecated("Use `getOrThrow` instead") let getExn: t<'a, 'b> => 'a +/** +`getOrThrow(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception + +## Examples + +```rescript +Belt.Result.Ok(42) +->Belt.Result.getOrThrow +->assertEqual(42) + + +switch Belt.Result.getOrThrow(Belt.Result.Error("Invalid data")) { // raise a exception +| exception _ => assert(true) +| _ => assert(false) +} +``` +*/ +let getOrThrow: t<'a, 'b> => 'a + @deprecated("Use `mapWithDefault` instead") let mapWithDefaultU: (t<'a, 'c>, 'b, 'a => 'b) => 'b /** From 7f33a5277d050b741a514f1b4b75d9bbbe2f2499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Sun, 29 Jun 2025 16:14:24 +0100 Subject: [PATCH 09/10] Update runtime JS output --- lib/es6/Belt_List.js | 15 ++++++++++++--- lib/es6/Belt_MutableQueue.js | 10 ++++++++-- lib/es6/Belt_Option.js | 5 ++++- lib/es6/Belt_Result.js | 5 ++++- lib/es6/Belt_Set.js | 7 +++++-- lib/js/Belt_List.js | 15 ++++++++++++--- lib/js/Belt_MutableQueue.js | 10 ++++++++-- lib/js/Belt_Option.js | 5 ++++- lib/js/Belt_Result.js | 5 ++++- lib/js/Belt_Set.js | 7 +++++-- 10 files changed, 66 insertions(+), 18 deletions(-) diff --git a/lib/es6/Belt_List.js b/lib/es6/Belt_List.js index f7cf86aa06..6b0bdd9f4f 100644 --- a/lib/es6/Belt_List.js +++ b/lib/es6/Belt_List.js @@ -11,7 +11,7 @@ function head(x) { } -function headExn(x) { +function headOrThrow(x) { if (x !== 0) { return x.hd; } @@ -28,7 +28,7 @@ function tail(x) { } -function tailExn(x) { +function tailOrThrow(x) { if (x !== 0) { return x.tl; } @@ -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", @@ -1286,6 +1286,12 @@ function zip(l1, l2) { let size = length; +let headExn = headOrThrow; + +let tailExn = tailOrThrow; + +let getExn = getOrThrow; + let makeByU = makeBy; let mapU = map; @@ -1357,11 +1363,14 @@ export { size, head, headExn, + headOrThrow, tail, tailExn, + tailOrThrow, add, get, getExn, + getOrThrow, make, makeByU, makeBy, diff --git a/lib/es6/Belt_MutableQueue.js b/lib/es6/Belt_MutableQueue.js index 525394c06d..a3a23b5aa3 100644 --- a/lib/es6/Belt_MutableQueue.js +++ b/lib/es6/Belt_MutableQueue.js @@ -49,7 +49,7 @@ function peekUndefined(q) { } -function peekExn(q) { +function peekOrThrow(q) { let v = q.first; if (v !== undefined) { return v.content; @@ -76,7 +76,7 @@ function pop(q) { } } -function popExn(q) { +function popOrThrow(q) { let x = q.first; if (x !== undefined) { let next = x.next; @@ -260,6 +260,10 @@ function fromArray(arr) { return q; } +let peekExn = peekOrThrow; + +let popExn = popOrThrow; + let mapU = map; let forEachU = forEach; @@ -275,9 +279,11 @@ export { peek, peekUndefined, peekExn, + peekOrThrow, pop, popUndefined, popExn, + popOrThrow, copy, size, mapU, diff --git a/lib/es6/Belt_Option.js b/lib/es6/Belt_Option.js index 9de1fb377b..a322681d26 100644 --- a/lib/es6/Belt_Option.js +++ b/lib/es6/Belt_Option.js @@ -16,7 +16,7 @@ function forEach(opt, f) { } -function getExn(x) { +function getOrThrow(x) { if (x !== undefined) { return Primitive_option.valFromOption(x); } @@ -102,6 +102,8 @@ let keepU = keep; let forEachU = forEach; +let getExn = getOrThrow; + let mapWithDefaultU = mapWithDefault; let mapU = map; @@ -118,6 +120,7 @@ export { forEachU, forEach, getExn, + getOrThrow, mapWithDefaultU, mapWithDefault, mapU, diff --git a/lib/es6/Belt_Result.js b/lib/es6/Belt_Result.js index e534ddd9fe..b8c9739a81 100644 --- a/lib/es6/Belt_Result.js +++ b/lib/es6/Belt_Result.js @@ -1,7 +1,7 @@ -function getExn(x) { +function getOrThrow(x) { if (x.TAG === "Ok") { return x._0; } @@ -86,6 +86,8 @@ function cmp(a, b, f) { } } +let getExn = getOrThrow; + let mapWithDefaultU = mapWithDefault; let mapU = map; @@ -98,6 +100,7 @@ let cmpU = cmp; export { getExn, + getOrThrow, mapWithDefaultU, mapWithDefault, mapU, diff --git a/lib/es6/Belt_Set.js b/lib/es6/Belt_Set.js index d568b56efd..68266291d7 100644 --- a/lib/es6/Belt_Set.js +++ b/lib/es6/Belt_Set.js @@ -196,8 +196,8 @@ function getUndefined(m, e) { return Belt_SetDict.getUndefined(m.data, e, m.cmp); } -function getExn(m, e) { - return Belt_SetDict.getExn(m.data, e, m.cmp); +function getOrThrow(m, e) { + return Belt_SetDict.getOrThrow(m.data, e, m.cmp); } function has(m, e) { @@ -251,6 +251,8 @@ let keepU = keep; let partitionU = partition; +let getExn = getOrThrow; + export { Int, $$String, @@ -292,6 +294,7 @@ export { get, getUndefined, getExn, + getOrThrow, split, checkInvariantInternal, getData, diff --git a/lib/js/Belt_List.js b/lib/js/Belt_List.js index 0dd1ac9145..67a8420ea1 100644 --- a/lib/js/Belt_List.js +++ b/lib/js/Belt_List.js @@ -11,7 +11,7 @@ function head(x) { } -function headExn(x) { +function headOrThrow(x) { if (x !== 0) { return x.hd; } @@ -28,7 +28,7 @@ function tail(x) { } -function tailExn(x) { +function tailOrThrow(x) { if (x !== 0) { return x.tl; } @@ -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", @@ -1286,6 +1286,12 @@ function zip(l1, l2) { let size = length; +let headExn = headOrThrow; + +let tailExn = tailOrThrow; + +let getExn = getOrThrow; + let makeByU = makeBy; let mapU = map; @@ -1356,11 +1362,14 @@ 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.makeByU = makeByU; exports.makeBy = makeBy; diff --git a/lib/js/Belt_MutableQueue.js b/lib/js/Belt_MutableQueue.js index f3de22ba14..cdc9588cc5 100644 --- a/lib/js/Belt_MutableQueue.js +++ b/lib/js/Belt_MutableQueue.js @@ -49,7 +49,7 @@ function peekUndefined(q) { } -function peekExn(q) { +function peekOrThrow(q) { let v = q.first; if (v !== undefined) { return v.content; @@ -76,7 +76,7 @@ function pop(q) { } } -function popExn(q) { +function popOrThrow(q) { let x = q.first; if (x !== undefined) { let next = x.next; @@ -260,6 +260,10 @@ function fromArray(arr) { return q; } +let peekExn = peekOrThrow; + +let popExn = popOrThrow; + let mapU = map; let forEachU = forEach; @@ -274,9 +278,11 @@ exports.add = add; exports.peek = peek; exports.peekUndefined = peekUndefined; exports.peekExn = peekExn; +exports.peekOrThrow = peekOrThrow; exports.pop = pop; exports.popUndefined = popUndefined; exports.popExn = popExn; +exports.popOrThrow = popOrThrow; exports.copy = copy; exports.size = size; exports.mapU = mapU; diff --git a/lib/js/Belt_Option.js b/lib/js/Belt_Option.js index 87c9d7d20d..3148003850 100644 --- a/lib/js/Belt_Option.js +++ b/lib/js/Belt_Option.js @@ -16,7 +16,7 @@ function forEach(opt, f) { } -function getExn(x) { +function getOrThrow(x) { if (x !== undefined) { return Primitive_option.valFromOption(x); } @@ -102,6 +102,8 @@ let keepU = keep; let forEachU = forEach; +let getExn = getOrThrow; + let mapWithDefaultU = mapWithDefault; let mapU = map; @@ -117,6 +119,7 @@ exports.keep = keep; exports.forEachU = forEachU; exports.forEach = forEach; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.mapWithDefaultU = mapWithDefaultU; exports.mapWithDefault = mapWithDefault; exports.mapU = mapU; diff --git a/lib/js/Belt_Result.js b/lib/js/Belt_Result.js index fb2585738a..004803e805 100644 --- a/lib/js/Belt_Result.js +++ b/lib/js/Belt_Result.js @@ -1,7 +1,7 @@ 'use strict'; -function getExn(x) { +function getOrThrow(x) { if (x.TAG === "Ok") { return x._0; } @@ -86,6 +86,8 @@ function cmp(a, b, f) { } } +let getExn = getOrThrow; + let mapWithDefaultU = mapWithDefault; let mapU = map; @@ -97,6 +99,7 @@ let eqU = eq; let cmpU = cmp; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.mapWithDefaultU = mapWithDefaultU; exports.mapWithDefault = mapWithDefault; exports.mapU = mapU; diff --git a/lib/js/Belt_Set.js b/lib/js/Belt_Set.js index f72785f12d..7776fa1639 100644 --- a/lib/js/Belt_Set.js +++ b/lib/js/Belt_Set.js @@ -196,8 +196,8 @@ function getUndefined(m, e) { return Belt_SetDict.getUndefined(m.data, e, m.cmp); } -function getExn(m, e) { - return Belt_SetDict.getExn(m.data, e, m.cmp); +function getOrThrow(m, e) { + return Belt_SetDict.getOrThrow(m.data, e, m.cmp); } function has(m, e) { @@ -251,6 +251,8 @@ let keepU = keep; let partitionU = partition; +let getExn = getOrThrow; + exports.Int = Int; exports.$$String = $$String; exports.Dict = Dict; @@ -291,6 +293,7 @@ exports.maxUndefined = maxUndefined; exports.get = get; exports.getUndefined = getUndefined; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.split = split; exports.checkInvariantInternal = checkInvariantInternal; exports.getData = getData; From 914560a6805b0a4bf451e00396daf5d5aa36126f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= Date: Sun, 29 Jun 2025 18:26:26 +0100 Subject: [PATCH 10/10] Add xxxOrThrow functions to specialised Belt Map and Set data structures --- lib/es6/Belt_MapInt.js | 5 ++++- lib/es6/Belt_MapString.js | 5 ++++- lib/es6/Belt_MutableMapInt.js | 7 +++++-- lib/es6/Belt_MutableMapString.js | 7 +++++-- lib/es6/Belt_MutableSetInt.js | 7 +++++-- lib/es6/Belt_MutableSetString.js | 7 +++++-- lib/es6/Belt_SetInt.js | 5 ++++- lib/es6/Belt_SetString.js | 5 ++++- lib/es6/Belt_internalMapInt.js | 4 ++-- lib/es6/Belt_internalMapString.js | 4 ++-- lib/es6/Belt_internalSetInt.js | 4 ++-- lib/es6/Belt_internalSetString.js | 4 ++-- lib/js/Belt_MapInt.js | 5 ++++- lib/js/Belt_MapString.js | 5 ++++- lib/js/Belt_MutableMapInt.js | 7 +++++-- lib/js/Belt_MutableMapString.js | 7 +++++-- lib/js/Belt_MutableSetInt.js | 7 +++++-- lib/js/Belt_MutableSetString.js | 7 +++++-- lib/js/Belt_SetInt.js | 5 ++++- lib/js/Belt_SetString.js | 5 ++++- lib/js/Belt_internalMapInt.js | 4 ++-- lib/js/Belt_internalMapString.js | 4 ++-- lib/js/Belt_internalSetInt.js | 4 ++-- lib/js/Belt_internalSetString.js | 4 ++-- runtime/Belt_MapInt.res | 3 ++- runtime/Belt_MapInt.resi | 3 +++ runtime/Belt_MapString.res | 3 ++- runtime/Belt_MapString.resi | 3 +++ runtime/Belt_MutableMapInt.res | 3 ++- runtime/Belt_MutableMapInt.resi | 2 ++ runtime/Belt_MutableMapString.res | 3 ++- runtime/Belt_MutableMapString.resi | 2 ++ runtime/Belt_MutableSetInt.res | 3 ++- runtime/Belt_MutableSetInt.resi | 2 ++ runtime/Belt_MutableSetString.res | 3 ++- runtime/Belt_MutableSetString.resi | 2 ++ runtime/Belt_SetInt.res | 3 ++- runtime/Belt_SetInt.resi | 3 +++ runtime/Belt_SetString.res | 3 ++- runtime/Belt_SetString.resi | 3 +++ runtime/Belt_internalMapInt.res | 4 ++-- runtime/Belt_internalMapString.res | 4 ++-- runtime/Belt_internalSetInt.res | 4 ++-- runtime/Belt_internalSetString.res | 4 ++-- 44 files changed, 132 insertions(+), 56 deletions(-) diff --git a/lib/es6/Belt_MapInt.js b/lib/es6/Belt_MapInt.js index e8d85d0381..99352cdf78 100644 --- a/lib/es6/Belt_MapInt.js +++ b/lib/es6/Belt_MapInt.js @@ -218,7 +218,9 @@ let getUndefined = Belt_internalMapInt.getUndefined; let getWithDefault = Belt_internalMapInt.getWithDefault; -let getExn = Belt_internalMapInt.getExn; +let getExn = Belt_internalMapInt.getOrThrow; + +let getOrThrow = Belt_internalMapInt.getOrThrow; let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal; @@ -282,6 +284,7 @@ export { getUndefined, getWithDefault, getExn, + getOrThrow, checkInvariantInternal, remove, removeMany, diff --git a/lib/es6/Belt_MapString.js b/lib/es6/Belt_MapString.js index 6fad25c406..6aba64e3b2 100644 --- a/lib/es6/Belt_MapString.js +++ b/lib/es6/Belt_MapString.js @@ -218,7 +218,9 @@ let getUndefined = Belt_internalMapString.getUndefined; let getWithDefault = Belt_internalMapString.getWithDefault; -let getExn = Belt_internalMapString.getExn; +let getExn = Belt_internalMapString.getOrThrow; + +let getOrThrow = Belt_internalMapString.getOrThrow; let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal; @@ -282,6 +284,7 @@ export { getUndefined, getWithDefault, getExn, + getOrThrow, checkInvariantInternal, remove, removeMany, diff --git a/lib/es6/Belt_MutableMapInt.js b/lib/es6/Belt_MutableMapInt.js index 1bb47aa27f..a3aef75080 100644 --- a/lib/es6/Belt_MutableMapInt.js +++ b/lib/es6/Belt_MutableMapInt.js @@ -272,8 +272,8 @@ function getWithDefault(d, x, def) { return Belt_internalMapInt.getWithDefault(d.data, x, def); } -function getExn(d, x) { - return Belt_internalMapInt.getExn(d.data, x); +function getOrThrow(d, x) { + return Belt_internalMapInt.getOrThrow(d.data, x); } let cmpU = cmp; @@ -288,6 +288,8 @@ let everyU = every; let someU = some; +let getExn = getOrThrow; + let updateU = update; let mapU = map; @@ -329,6 +331,7 @@ export { getUndefined, getWithDefault, getExn, + getOrThrow, checkInvariantInternal, remove, removeMany, diff --git a/lib/es6/Belt_MutableMapString.js b/lib/es6/Belt_MutableMapString.js index a6e8c4a825..beb6c675bd 100644 --- a/lib/es6/Belt_MutableMapString.js +++ b/lib/es6/Belt_MutableMapString.js @@ -272,8 +272,8 @@ function getWithDefault(d, x, def) { return Belt_internalMapString.getWithDefault(d.data, x, def); } -function getExn(d, x) { - return Belt_internalMapString.getExn(d.data, x); +function getOrThrow(d, x) { + return Belt_internalMapString.getOrThrow(d.data, x); } let cmpU = cmp; @@ -288,6 +288,8 @@ let everyU = every; let someU = some; +let getExn = getOrThrow; + let updateU = update; let mapU = map; @@ -329,6 +331,7 @@ export { getUndefined, getWithDefault, getExn, + getOrThrow, checkInvariantInternal, remove, removeMany, diff --git a/lib/es6/Belt_MutableSetInt.js b/lib/es6/Belt_MutableSetInt.js index b02146bddf..b725898682 100644 --- a/lib/es6/Belt_MutableSetInt.js +++ b/lib/es6/Belt_MutableSetInt.js @@ -270,8 +270,8 @@ function getUndefined(d, x) { return Belt_internalSetInt.getUndefined(d.data, x); } -function getExn(d, x) { - return Belt_internalSetInt.getExn(d.data, x); +function getOrThrow(d, x) { + return Belt_internalSetInt.getOrThrow(d.data, x); } function split(d, key) { @@ -442,6 +442,8 @@ let keepU = keep; let partitionU = partition; +let getExn = getOrThrow; + export { make, fromArray, @@ -483,6 +485,7 @@ export { get, getUndefined, getExn, + getOrThrow, split, checkInvariantInternal, } diff --git a/lib/es6/Belt_MutableSetString.js b/lib/es6/Belt_MutableSetString.js index 02d7331b4a..a1bd02c9e1 100644 --- a/lib/es6/Belt_MutableSetString.js +++ b/lib/es6/Belt_MutableSetString.js @@ -270,8 +270,8 @@ function getUndefined(d, x) { return Belt_internalSetString.getUndefined(d.data, x); } -function getExn(d, x) { - return Belt_internalSetString.getExn(d.data, x); +function getOrThrow(d, x) { + return Belt_internalSetString.getOrThrow(d.data, x); } function split(d, key) { @@ -442,6 +442,8 @@ let keepU = keep; let partitionU = partition; +let getExn = getOrThrow; + export { make, fromArray, @@ -483,6 +485,7 @@ export { get, getUndefined, getExn, + getOrThrow, split, checkInvariantInternal, } diff --git a/lib/es6/Belt_SetInt.js b/lib/es6/Belt_SetInt.js index 01999f1011..0867aaabb8 100644 --- a/lib/es6/Belt_SetInt.js +++ b/lib/es6/Belt_SetInt.js @@ -311,7 +311,9 @@ let get = Belt_internalSetInt.get; let getUndefined = Belt_internalSetInt.getUndefined; -let getExn = Belt_internalSetInt.getExn; +let getExn = Belt_internalSetInt.getOrThrow; + +let getOrThrow = Belt_internalSetInt.getOrThrow; let checkInvariantInternal = Belt_internalAVLset.checkInvariantInternal; @@ -353,6 +355,7 @@ export { get, getUndefined, getExn, + getOrThrow, split, checkInvariantInternal, } diff --git a/lib/es6/Belt_SetString.js b/lib/es6/Belt_SetString.js index ff9fa6cb90..c7741d82eb 100644 --- a/lib/es6/Belt_SetString.js +++ b/lib/es6/Belt_SetString.js @@ -311,7 +311,9 @@ let get = Belt_internalSetString.get; let getUndefined = Belt_internalSetString.getUndefined; -let getExn = Belt_internalSetString.getExn; +let getExn = Belt_internalSetString.getOrThrow; + +let getOrThrow = Belt_internalSetString.getOrThrow; let checkInvariantInternal = Belt_internalAVLset.checkInvariantInternal; @@ -353,6 +355,7 @@ export { get, getUndefined, getExn, + getOrThrow, split, checkInvariantInternal, } diff --git a/lib/es6/Belt_internalMapInt.js b/lib/es6/Belt_internalMapInt.js index 292662c21a..b21c0df5a8 100644 --- a/lib/es6/Belt_internalMapInt.js +++ b/lib/es6/Belt_internalMapInt.js @@ -51,7 +51,7 @@ function getUndefined(_n, x) { }; } -function getExn(_n, x) { +function getOrThrow(_n, x) { while (true) { let n = _n; if (n !== undefined) { @@ -336,7 +336,7 @@ export { add, get, getUndefined, - getExn, + getOrThrow, getWithDefault, has, remove, diff --git a/lib/es6/Belt_internalMapString.js b/lib/es6/Belt_internalMapString.js index a156d6bc44..243d0d90ef 100644 --- a/lib/es6/Belt_internalMapString.js +++ b/lib/es6/Belt_internalMapString.js @@ -51,7 +51,7 @@ function getUndefined(_n, x) { }; } -function getExn(_n, x) { +function getOrThrow(_n, x) { while (true) { let n = _n; if (n !== undefined) { @@ -336,7 +336,7 @@ export { add, get, getUndefined, - getExn, + getOrThrow, getWithDefault, has, remove, diff --git a/lib/es6/Belt_internalSetInt.js b/lib/es6/Belt_internalSetInt.js index 53d46e6d7e..3c2b2d707a 100644 --- a/lib/es6/Belt_internalSetInt.js +++ b/lib/es6/Belt_internalSetInt.js @@ -130,7 +130,7 @@ function getUndefined(_n, x) { }; } -function getExn(_n, x) { +function getOrThrow(_n, x) { while (true) { let n = _n; if (n !== undefined) { @@ -202,7 +202,7 @@ export { subset, get, getUndefined, - getExn, + getOrThrow, addMutate, fromArray, } diff --git a/lib/es6/Belt_internalSetString.js b/lib/es6/Belt_internalSetString.js index 75c0c3e8da..302b1a0652 100644 --- a/lib/es6/Belt_internalSetString.js +++ b/lib/es6/Belt_internalSetString.js @@ -130,7 +130,7 @@ function getUndefined(_n, x) { }; } -function getExn(_n, x) { +function getOrThrow(_n, x) { while (true) { let n = _n; if (n !== undefined) { @@ -202,7 +202,7 @@ export { subset, get, getUndefined, - getExn, + getOrThrow, addMutate, fromArray, } diff --git a/lib/js/Belt_MapInt.js b/lib/js/Belt_MapInt.js index e857ca95fe..2af4751304 100644 --- a/lib/js/Belt_MapInt.js +++ b/lib/js/Belt_MapInt.js @@ -218,7 +218,9 @@ let getUndefined = Belt_internalMapInt.getUndefined; let getWithDefault = Belt_internalMapInt.getWithDefault; -let getExn = Belt_internalMapInt.getExn; +let getExn = Belt_internalMapInt.getOrThrow; + +let getOrThrow = Belt_internalMapInt.getOrThrow; let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal; @@ -281,6 +283,7 @@ exports.get = get; exports.getUndefined = getUndefined; exports.getWithDefault = getWithDefault; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.checkInvariantInternal = checkInvariantInternal; exports.remove = remove; exports.removeMany = removeMany; diff --git a/lib/js/Belt_MapString.js b/lib/js/Belt_MapString.js index 5745f2f342..176f0398d2 100644 --- a/lib/js/Belt_MapString.js +++ b/lib/js/Belt_MapString.js @@ -218,7 +218,9 @@ let getUndefined = Belt_internalMapString.getUndefined; let getWithDefault = Belt_internalMapString.getWithDefault; -let getExn = Belt_internalMapString.getExn; +let getExn = Belt_internalMapString.getOrThrow; + +let getOrThrow = Belt_internalMapString.getOrThrow; let checkInvariantInternal = Belt_internalAVLtree.checkInvariantInternal; @@ -281,6 +283,7 @@ exports.get = get; exports.getUndefined = getUndefined; exports.getWithDefault = getWithDefault; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.checkInvariantInternal = checkInvariantInternal; exports.remove = remove; exports.removeMany = removeMany; diff --git a/lib/js/Belt_MutableMapInt.js b/lib/js/Belt_MutableMapInt.js index 12d327cc3a..f8f1ab1102 100644 --- a/lib/js/Belt_MutableMapInt.js +++ b/lib/js/Belt_MutableMapInt.js @@ -272,8 +272,8 @@ function getWithDefault(d, x, def) { return Belt_internalMapInt.getWithDefault(d.data, x, def); } -function getExn(d, x) { - return Belt_internalMapInt.getExn(d.data, x); +function getOrThrow(d, x) { + return Belt_internalMapInt.getOrThrow(d.data, x); } let cmpU = cmp; @@ -288,6 +288,8 @@ let everyU = every; let someU = some; +let getExn = getOrThrow; + let updateU = update; let mapU = map; @@ -328,6 +330,7 @@ exports.get = get; exports.getUndefined = getUndefined; exports.getWithDefault = getWithDefault; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.checkInvariantInternal = checkInvariantInternal; exports.remove = remove; exports.removeMany = removeMany; diff --git a/lib/js/Belt_MutableMapString.js b/lib/js/Belt_MutableMapString.js index 8409126130..21dedc4f3e 100644 --- a/lib/js/Belt_MutableMapString.js +++ b/lib/js/Belt_MutableMapString.js @@ -272,8 +272,8 @@ function getWithDefault(d, x, def) { return Belt_internalMapString.getWithDefault(d.data, x, def); } -function getExn(d, x) { - return Belt_internalMapString.getExn(d.data, x); +function getOrThrow(d, x) { + return Belt_internalMapString.getOrThrow(d.data, x); } let cmpU = cmp; @@ -288,6 +288,8 @@ let everyU = every; let someU = some; +let getExn = getOrThrow; + let updateU = update; let mapU = map; @@ -328,6 +330,7 @@ exports.get = get; exports.getUndefined = getUndefined; exports.getWithDefault = getWithDefault; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.checkInvariantInternal = checkInvariantInternal; exports.remove = remove; exports.removeMany = removeMany; diff --git a/lib/js/Belt_MutableSetInt.js b/lib/js/Belt_MutableSetInt.js index 34bf747ceb..77f9699739 100644 --- a/lib/js/Belt_MutableSetInt.js +++ b/lib/js/Belt_MutableSetInt.js @@ -270,8 +270,8 @@ function getUndefined(d, x) { return Belt_internalSetInt.getUndefined(d.data, x); } -function getExn(d, x) { - return Belt_internalSetInt.getExn(d.data, x); +function getOrThrow(d, x) { + return Belt_internalSetInt.getOrThrow(d.data, x); } function split(d, key) { @@ -442,6 +442,8 @@ let keepU = keep; let partitionU = partition; +let getExn = getOrThrow; + exports.make = make; exports.fromArray = fromArray; exports.fromSortedArrayUnsafe = fromSortedArrayUnsafe; @@ -482,6 +484,7 @@ exports.maxUndefined = maxUndefined; exports.get = get; exports.getUndefined = getUndefined; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.split = split; exports.checkInvariantInternal = checkInvariantInternal; /* No side effect */ diff --git a/lib/js/Belt_MutableSetString.js b/lib/js/Belt_MutableSetString.js index 88c07a3f28..57f8266f66 100644 --- a/lib/js/Belt_MutableSetString.js +++ b/lib/js/Belt_MutableSetString.js @@ -270,8 +270,8 @@ function getUndefined(d, x) { return Belt_internalSetString.getUndefined(d.data, x); } -function getExn(d, x) { - return Belt_internalSetString.getExn(d.data, x); +function getOrThrow(d, x) { + return Belt_internalSetString.getOrThrow(d.data, x); } function split(d, key) { @@ -442,6 +442,8 @@ let keepU = keep; let partitionU = partition; +let getExn = getOrThrow; + exports.make = make; exports.fromArray = fromArray; exports.fromSortedArrayUnsafe = fromSortedArrayUnsafe; @@ -482,6 +484,7 @@ exports.maxUndefined = maxUndefined; exports.get = get; exports.getUndefined = getUndefined; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.split = split; exports.checkInvariantInternal = checkInvariantInternal; /* No side effect */ diff --git a/lib/js/Belt_SetInt.js b/lib/js/Belt_SetInt.js index f066e2d7d2..588fa5b2f8 100644 --- a/lib/js/Belt_SetInt.js +++ b/lib/js/Belt_SetInt.js @@ -311,7 +311,9 @@ let get = Belt_internalSetInt.get; let getUndefined = Belt_internalSetInt.getUndefined; -let getExn = Belt_internalSetInt.getExn; +let getExn = Belt_internalSetInt.getOrThrow; + +let getOrThrow = Belt_internalSetInt.getOrThrow; let checkInvariantInternal = Belt_internalAVLset.checkInvariantInternal; @@ -352,6 +354,7 @@ exports.maxUndefined = maxUndefined; exports.get = get; exports.getUndefined = getUndefined; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.split = split; exports.checkInvariantInternal = checkInvariantInternal; /* No side effect */ diff --git a/lib/js/Belt_SetString.js b/lib/js/Belt_SetString.js index 3eb786ba53..6eb60bbb43 100644 --- a/lib/js/Belt_SetString.js +++ b/lib/js/Belt_SetString.js @@ -311,7 +311,9 @@ let get = Belt_internalSetString.get; let getUndefined = Belt_internalSetString.getUndefined; -let getExn = Belt_internalSetString.getExn; +let getExn = Belt_internalSetString.getOrThrow; + +let getOrThrow = Belt_internalSetString.getOrThrow; let checkInvariantInternal = Belt_internalAVLset.checkInvariantInternal; @@ -352,6 +354,7 @@ exports.maxUndefined = maxUndefined; exports.get = get; exports.getUndefined = getUndefined; exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.split = split; exports.checkInvariantInternal = checkInvariantInternal; /* No side effect */ diff --git a/lib/js/Belt_internalMapInt.js b/lib/js/Belt_internalMapInt.js index ed9658e9bb..22b66b1625 100644 --- a/lib/js/Belt_internalMapInt.js +++ b/lib/js/Belt_internalMapInt.js @@ -51,7 +51,7 @@ function getUndefined(_n, x) { }; } -function getExn(_n, x) { +function getOrThrow(_n, x) { while (true) { let n = _n; if (n !== undefined) { @@ -335,7 +335,7 @@ exports.S = S; exports.add = add; exports.get = get; exports.getUndefined = getUndefined; -exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.getWithDefault = getWithDefault; exports.has = has; exports.remove = remove; diff --git a/lib/js/Belt_internalMapString.js b/lib/js/Belt_internalMapString.js index e648ebefd7..dc0aa2b072 100644 --- a/lib/js/Belt_internalMapString.js +++ b/lib/js/Belt_internalMapString.js @@ -51,7 +51,7 @@ function getUndefined(_n, x) { }; } -function getExn(_n, x) { +function getOrThrow(_n, x) { while (true) { let n = _n; if (n !== undefined) { @@ -335,7 +335,7 @@ exports.S = S; exports.add = add; exports.get = get; exports.getUndefined = getUndefined; -exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.getWithDefault = getWithDefault; exports.has = has; exports.remove = remove; diff --git a/lib/js/Belt_internalSetInt.js b/lib/js/Belt_internalSetInt.js index 093dca6bd1..327af8e73c 100644 --- a/lib/js/Belt_internalSetInt.js +++ b/lib/js/Belt_internalSetInt.js @@ -130,7 +130,7 @@ function getUndefined(_n, x) { }; } -function getExn(_n, x) { +function getOrThrow(_n, x) { while (true) { let n = _n; if (n !== undefined) { @@ -201,7 +201,7 @@ exports.eq = eq; exports.subset = subset; exports.get = get; exports.getUndefined = getUndefined; -exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.addMutate = addMutate; exports.fromArray = fromArray; /* No side effect */ diff --git a/lib/js/Belt_internalSetString.js b/lib/js/Belt_internalSetString.js index d08cce4212..917dbe8acb 100644 --- a/lib/js/Belt_internalSetString.js +++ b/lib/js/Belt_internalSetString.js @@ -130,7 +130,7 @@ function getUndefined(_n, x) { }; } -function getExn(_n, x) { +function getOrThrow(_n, x) { while (true) { let n = _n; if (n !== undefined) { @@ -201,7 +201,7 @@ exports.eq = eq; exports.subset = subset; exports.get = get; exports.getUndefined = getUndefined; -exports.getExn = getExn; +exports.getOrThrow = getOrThrow; exports.addMutate = addMutate; exports.fromArray = fromArray; /* No side effect */ diff --git a/runtime/Belt_MapInt.res b/runtime/Belt_MapInt.res index 9b06803bc2..2ce7d0d151 100644 --- a/runtime/Belt_MapInt.res +++ b/runtime/Belt_MapInt.res @@ -171,7 +171,8 @@ let eq = I.eq let get = I.get let getUndefined = I.getUndefined let getWithDefault = I.getWithDefault -let getExn = I.getExn +let getOrThrow = I.getOrThrow +let getExn = getOrThrow let split = I.split let merge = I.merge let fromArray = I.fromArray diff --git a/runtime/Belt_MapInt.resi b/runtime/Belt_MapInt.resi index 0279527499..95178e574e 100644 --- a/runtime/Belt_MapInt.resi +++ b/runtime/Belt_MapInt.resi @@ -114,8 +114,11 @@ let getUndefined: (t<'v>, key) => Js.undefined<'v> let getWithDefault: (t<'v>, key, 'v) => 'v +@deprecated("Use `getOrThrow` instead") let getExn: (t<'v>, key) => 'v +let getOrThrow: (t<'v>, key) => 'v + /** **raise** when invariant is not held */ diff --git a/runtime/Belt_MapString.res b/runtime/Belt_MapString.res index b0841df53e..af592d6c2c 100644 --- a/runtime/Belt_MapString.res +++ b/runtime/Belt_MapString.res @@ -171,7 +171,8 @@ let eq = I.eq let get = I.get let getUndefined = I.getUndefined let getWithDefault = I.getWithDefault -let getExn = I.getExn +let getOrThrow = I.getOrThrow +let getExn = getOrThrow let split = I.split let merge = I.merge let fromArray = I.fromArray diff --git a/runtime/Belt_MapString.resi b/runtime/Belt_MapString.resi index 1a02bd2c1f..b41f6af754 100644 --- a/runtime/Belt_MapString.resi +++ b/runtime/Belt_MapString.resi @@ -114,8 +114,11 @@ let getUndefined: (t<'v>, key) => Js.undefined<'v> let getWithDefault: (t<'v>, key, 'v) => 'v +@deprecated("Use `getOrThrow` instead") let getExn: (t<'v>, key) => 'v +let getOrThrow: (t<'v>, key) => 'v + /** **raise** when invariant is not held */ diff --git a/runtime/Belt_MutableMapInt.res b/runtime/Belt_MutableMapInt.res index 31f145d7b6..9f0209a523 100644 --- a/runtime/Belt_MutableMapInt.res +++ b/runtime/Belt_MutableMapInt.res @@ -165,7 +165,8 @@ let eq = (d0, d1, f) => I.eq(d0.data, d1.data, f) let get = (d, x) => I.get(d.data, x) let getUndefined = (d, x) => I.getUndefined(d.data, x) let getWithDefault = (d, x, def) => I.getWithDefault(d.data, x, def) -let getExn = (d, x) => I.getExn(d.data, x) +let getOrThrow = (d, x) => I.getOrThrow(d.data, x) +let getExn = getOrThrow let cmpU = cmp let eqU = eq diff --git a/runtime/Belt_MutableMapInt.resi b/runtime/Belt_MutableMapInt.resi index 7319d0f2ea..14fc79f744 100644 --- a/runtime/Belt_MutableMapInt.resi +++ b/runtime/Belt_MutableMapInt.resi @@ -105,7 +105,9 @@ let maxUndefined: t<'a> => Js.undefined<(key, 'a)> let get: (t<'a>, key) => option<'a> let getUndefined: (t<'a>, key) => Js.undefined<'a> let getWithDefault: (t<'a>, key, 'a) => 'a +@deprecated("Use `getOrThrow` instead") let getExn: (t<'a>, key) => 'a +let getOrThrow: (t<'a>, key) => 'a /** **raise** when invariant is not held diff --git a/runtime/Belt_MutableMapString.res b/runtime/Belt_MutableMapString.res index e3010ef885..8d1a38d4ca 100644 --- a/runtime/Belt_MutableMapString.res +++ b/runtime/Belt_MutableMapString.res @@ -165,7 +165,8 @@ let eq = (d0, d1, f) => I.eq(d0.data, d1.data, f) let get = (d, x) => I.get(d.data, x) let getUndefined = (d, x) => I.getUndefined(d.data, x) let getWithDefault = (d, x, def) => I.getWithDefault(d.data, x, def) -let getExn = (d, x) => I.getExn(d.data, x) +let getOrThrow = (d, x) => I.getOrThrow(d.data, x) +let getExn = getOrThrow let cmpU = cmp let eqU = eq diff --git a/runtime/Belt_MutableMapString.resi b/runtime/Belt_MutableMapString.resi index 4ae708d179..0e147c2482 100644 --- a/runtime/Belt_MutableMapString.resi +++ b/runtime/Belt_MutableMapString.resi @@ -105,7 +105,9 @@ let maxUndefined: t<'a> => Js.undefined<(key, 'a)> let get: (t<'a>, key) => option<'a> let getUndefined: (t<'a>, key) => Js.undefined<'a> let getWithDefault: (t<'a>, key, 'a) => 'a +@deprecated("Use `getOrThrow` instead") let getExn: (t<'a>, key) => 'a +let getOrThrow: (t<'a>, key) => 'a /** **raise** when invariant is not held diff --git a/runtime/Belt_MutableSetInt.res b/runtime/Belt_MutableSetInt.res index 3264258195..3bceb489a2 100644 --- a/runtime/Belt_MutableSetInt.res +++ b/runtime/Belt_MutableSetInt.res @@ -218,7 +218,8 @@ let cmp = (d0, d1) => I.cmp(d0.data, d1.data) let eq = (d0, d1) => I.eq(d0.data, d1.data) let get = (d, x) => I.get(d.data, x) let getUndefined = (d, x) => I.getUndefined(d.data, x) -let getExn = (d, x) => I.getExn(d.data, x) +let getOrThrow = (d, x) => I.getOrThrow(d.data, x) +let getExn = getOrThrow let split = (d, key) => { let arr = N.toArray(d.data) diff --git a/runtime/Belt_MutableSetInt.resi b/runtime/Belt_MutableSetInt.resi index 1ee03404c0..e946eb3a48 100644 --- a/runtime/Belt_MutableSetInt.resi +++ b/runtime/Belt_MutableSetInt.resi @@ -124,7 +124,9 @@ let maxUndefined: t => Js.undefined let get: (t, value) => option let getUndefined: (t, value) => Js.undefined +@deprecated("Use `getOrThrow` instead") let getExn: (t, value) => value +let getOrThrow: (t, value) => value /** `split(s, key)` return a fresh copy of each diff --git a/runtime/Belt_MutableSetString.res b/runtime/Belt_MutableSetString.res index db94836223..454d3244b4 100644 --- a/runtime/Belt_MutableSetString.res +++ b/runtime/Belt_MutableSetString.res @@ -218,7 +218,8 @@ let cmp = (d0, d1) => I.cmp(d0.data, d1.data) let eq = (d0, d1) => I.eq(d0.data, d1.data) let get = (d, x) => I.get(d.data, x) let getUndefined = (d, x) => I.getUndefined(d.data, x) -let getExn = (d, x) => I.getExn(d.data, x) +let getOrThrow = (d, x) => I.getOrThrow(d.data, x) +let getExn = getOrThrow let split = (d, key) => { let arr = N.toArray(d.data) diff --git a/runtime/Belt_MutableSetString.resi b/runtime/Belt_MutableSetString.resi index 4b825f2bf1..e7f00376d7 100644 --- a/runtime/Belt_MutableSetString.resi +++ b/runtime/Belt_MutableSetString.resi @@ -124,7 +124,9 @@ let maxUndefined: t => Js.undefined let get: (t, value) => option let getUndefined: (t, value) => Js.undefined +@deprecated("Use `getOrThrow` instead") let getExn: (t, value) => value +let getOrThrow: (t, value) => value /** `split(s, key)` return a fresh copy of each diff --git a/runtime/Belt_SetInt.res b/runtime/Belt_SetInt.res index 0f294c1723..238516c821 100644 --- a/runtime/Belt_SetInt.res +++ b/runtime/Belt_SetInt.res @@ -109,7 +109,8 @@ let cmp = I.cmp let eq = I.eq let get = I.get let getUndefined = I.getUndefined -let getExn = I.getExn +let getOrThrow = I.getOrThrow +let getExn = getOrThrow let subset = I.subset let has = I.has diff --git a/runtime/Belt_SetInt.resi b/runtime/Belt_SetInt.resi index 4a31ca77f1..9273b24bed 100644 --- a/runtime/Belt_SetInt.resi +++ b/runtime/Belt_SetInt.resi @@ -152,8 +152,11 @@ let get: (t, value) => option let getUndefined: (t, value) => Js.undefined +@deprecated("Use `getOrThrow` instead") let getExn: (t, value) => value +let getOrThrow: (t, value) => value + /** `split(x, s)` returns a triple `(l, present, r)`, where `l` is the set of elements of `s` that are strictly less than `x`;`r` is the set of elements of diff --git a/runtime/Belt_SetString.res b/runtime/Belt_SetString.res index 73d20bb53c..7644cf724a 100644 --- a/runtime/Belt_SetString.res +++ b/runtime/Belt_SetString.res @@ -109,7 +109,8 @@ let cmp = I.cmp let eq = I.eq let get = I.get let getUndefined = I.getUndefined -let getExn = I.getExn +let getOrThrow = I.getOrThrow +let getExn = getOrThrow let subset = I.subset let has = I.has diff --git a/runtime/Belt_SetString.resi b/runtime/Belt_SetString.resi index 4c25b3f0ff..be6674aee8 100644 --- a/runtime/Belt_SetString.resi +++ b/runtime/Belt_SetString.resi @@ -152,8 +152,11 @@ let get: (t, value) => option let getUndefined: (t, value) => Js.undefined +@deprecated("Use `getOrThrow` instead") let getExn: (t, value) => value +let getOrThrow: (t, value) => value + /** `split(x, s)` returns a triple `(l, present, r)`, where `l` is the set of elements of `s` that are strictly less than `x`;`r` is the set of elements of diff --git a/runtime/Belt_internalMapInt.res b/runtime/Belt_internalMapInt.res index f51cef9417..8a750ca393 100644 --- a/runtime/Belt_internalMapInt.res +++ b/runtime/Belt_internalMapInt.res @@ -63,7 +63,7 @@ let rec getUndefined = (n, x: key) => } } -let rec getExn = (n, x: key) => +let rec getOrThrow = (n, x: key) => switch n { | None => throw(Not_found) | Some(n) => @@ -71,7 +71,7 @@ let rec getExn = (n, x: key) => if x == v { n.N.value } else { - getExn( + getOrThrow( if x < v { n.N.left } else { diff --git a/runtime/Belt_internalMapString.res b/runtime/Belt_internalMapString.res index 1fd5f024e2..000acdb147 100644 --- a/runtime/Belt_internalMapString.res +++ b/runtime/Belt_internalMapString.res @@ -63,7 +63,7 @@ let rec getUndefined = (n, x: key) => } } -let rec getExn = (n, x: key) => +let rec getOrThrow = (n, x: key) => switch n { | None => throw(Not_found) | Some(n) => @@ -71,7 +71,7 @@ let rec getExn = (n, x: key) => if x == v { n.N.value } else { - getExn( + getOrThrow( if x < v { n.N.left } else { diff --git a/runtime/Belt_internalSetInt.res b/runtime/Belt_internalSetInt.res index 6831794d34..c756d09d5a 100644 --- a/runtime/Belt_internalSetInt.res +++ b/runtime/Belt_internalSetInt.res @@ -104,7 +104,7 @@ let rec getUndefined = (n: t, x: value) => } } -let rec getExn = (n: t, x: value) => +let rec getOrThrow = (n: t, x: value) => switch n { | None => throw(Not_found) | Some(t) => @@ -112,7 +112,7 @@ let rec getExn = (n: t, x: value) => if x == v { v } else { - getExn( + getOrThrow( if x < v { t.left } else { diff --git a/runtime/Belt_internalSetString.res b/runtime/Belt_internalSetString.res index 3983818d48..bff62d1689 100644 --- a/runtime/Belt_internalSetString.res +++ b/runtime/Belt_internalSetString.res @@ -104,7 +104,7 @@ let rec getUndefined = (n: t, x: value) => } } -let rec getExn = (n: t, x: value) => +let rec getOrThrow = (n: t, x: value) => switch n { | None => throw(Not_found) | Some(t) => @@ -112,7 +112,7 @@ let rec getExn = (n: t, x: value) => if x == v { v } else { - getExn( + getOrThrow( if x < v { t.left } else {