Skip to content

Commit 084e44f

Browse files
committed
Add Belt.MutableQueue.peekOrThrow and popOrThrow
1 parent 7ea4cea commit 084e44f

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
- `Belt.List.getExn``Belt.List.getOrThrow`
5757
- `Belt.List.tailExn``Belt.List.tailOrThrow`
5858
- `Belt.List.headExn``Belt.List.headOrThrow`
59+
- `Belt.MutableQueue.peekExn``Belt.MutableQueue.peekOrThrow`
60+
- `Belt.MutableQueue.popExn``Belt.MutableQueue.popOrThrow`
5961
- Old functions remain available but are marked as deprecated with guidance to use the new `OrThrow` variants.
6062
- https://github.com/rescript-lang/rescript/pull/7518, https://github.com/rescript-lang/rescript/pull/7554, https://github.com/rescript-lang/rescript/pull/7581
6163

analysis/reanalyze/src/ExnLib.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ let raisesLibTable : (Name.t, Exceptions.t) Hashtbl.t =
2121
in
2222
let beltMap = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
2323
let beltMutableMap = beltMap in
24-
let beltMutableQueue = [("peekExn", [notFound]); ("popExn", [notFound])] in
24+
let beltMutableQueue =
25+
[
26+
("peekExn", [notFound]);
27+
("peekOrThrow", [notFound]);
28+
("popExn", [notFound]);
29+
("popOrThrow", [notFound]);
30+
]
31+
in
2532
let beltSet = [("getExn", [notFound]); ("getOrThrow", [notFound])] in
2633
let beltMutableSet = beltSet in
2734
let beltOption = [("getExn", [notFound])] in

runtime/Belt_MutableQueue.res

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ let peekUndefined = q =>
7070
| Some(v) => Js.Undefined.return(v.content)
7171
}
7272

73-
let peekExn = q =>
73+
let peekOrThrow = q =>
7474
switch q.first {
7575
| None => throw(Not_found)
7676
| Some(v) => v.content
7777
}
7878

79+
let peekExn = peekOrThrow
80+
7981
let pop = q =>
8082
switch q.first {
8183
| None => None
@@ -92,7 +94,7 @@ let pop = q =>
9294
}
9395
}
9496

95-
let popExn = q =>
97+
let popOrThrow = q =>
9698
/* TO fix */
9799
switch q.first {
98100
| None => throw(Not_found)
@@ -109,6 +111,8 @@ let popExn = q =>
109111
}
110112
}
111113

114+
let popExn = popOrThrow
115+
112116
let popUndefined = q =>
113117
switch q.first {
114118
| None => Js.undefined

runtime/Belt_MutableQueue.resi

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,16 @@ let peek: t<'a> => option<'a>
5959
let peekUndefined: t<'a> => Js.undefined<'a>
6060

6161
/**
62-
raise an exception if `q` is empty
62+
`peekExn(q)` raises an exception if `q` is empty.
6363
*/
64+
@deprecated("Use `peekOrThrow` instead")
6465
let peekExn: t<'a> => 'a
6566

67+
/**
68+
`peekOrThrow(q)` raises an exception if `q` is empty.
69+
*/
70+
let peekOrThrow: t<'a> => 'a
71+
6672
/**
6773
`pop(q)` removes and returns the first element in queue `q`.
6874
*/
@@ -77,8 +83,14 @@ let popUndefined: t<'a> => Js.undefined<'a>
7783
/**
7884
`popExn(q)` raise an exception if q is empty.
7985
*/
86+
@deprecated("Use `popOrThrow` instead")
8087
let popExn: t<'a> => 'a
8188

89+
/**
90+
`popOrThrow(q)` raise an exception if q is empty.
91+
*/
92+
let popOrThrow: t<'a> => 'a
93+
8294
/**
8395
`copy(q)` returns a fresh queue.
8496
*/

0 commit comments

Comments
 (0)