Skip to content

Commit e5ea4bf

Browse files
committed
Add Int.Ref.increment/decrement
1 parent c6142a3 commit e5ea4bf

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

lib/es6/Stdlib_Int.js

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function bitwiseNot(x) {
6666
return x ^ -1;
6767
}
6868

69+
let Ref = {};
70+
6971
let Constants = {
7072
minValue: -2147483648,
7173
maxValue: 2147483647
@@ -78,5 +80,6 @@ export {
7880
rangeWithOptions,
7981
clamp,
8082
bitwiseNot,
83+
Ref,
8184
}
8285
/* No side effect */

lib/js/Stdlib_Int.js

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function bitwiseNot(x) {
6666
return x ^ -1;
6767
}
6868

69+
let Ref = {};
70+
6971
let Constants = {
7072
minValue: -2147483648,
7173
maxValue: 2147483647
@@ -77,4 +79,5 @@ exports.range = range;
7779
exports.rangeWithOptions = rangeWithOptions;
7880
exports.clamp = clamp;
7981
exports.bitwiseNot = bitwiseNot;
82+
exports.Ref = Ref;
8083
/* No side effect */

runtime/Pervasives.res

+7-1
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,15 @@ external snd: (('a, 'b)) => 'b = "%field1"
293293

294294
type ref<'a> = {mutable contents: 'a}
295295
external ref: 'a => ref<'a> = "%makeref"
296-
external \"!": ref<'a> => 'a = "%refget"
297296
external \":=": (ref<'a>, 'a) => unit = "%refset"
297+
298+
@deprecated("Do not use. This will be removed in v13")
299+
external \"!": ref<'a> => 'a = "%refget"
300+
301+
@deprecated("Use `Int.Ref.increment` instead. This will be removed in v13")
298302
external incr: ref<int> => unit = "%incr"
303+
304+
@deprecated("Use `Int.Ref.decrement` instead. This will be removed in v13")
299305
external decr: ref<int> => unit = "%decr"
300306

301307
/* String conversion functions */

runtime/Stdlib_Int.res

+7
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,10 @@ external shiftRight: (int, int) => int = "%asrint"
107107
external shiftRightUnsigned: (int, int) => int = "%lsrint"
108108

109109
external ignore: int => unit = "%ignore"
110+
111+
module Ref = {
112+
type t = Pervasives.ref<int>
113+
114+
external increment: t => unit = "%incr"
115+
external decrement: t => unit = "%decr"
116+
}

runtime/Stdlib_Int.resi

+30
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,33 @@ external shiftRightUnsigned: (int, int) => int = "%lsrint"
482482
without having to store or process it further.
483483
*/
484484
external ignore: int => unit = "%ignore"
485+
486+
module Ref: {
487+
type t = Pervasives.ref<int>
488+
489+
/**
490+
`increment(intRef)` increments the value of the provided reference by 1.
491+
492+
## Examples
493+
494+
```rescript
495+
let myRef = ref(4)
496+
Int.Ref.increment(myRef)
497+
assertEqual(myRef.contents, 5)
498+
```
499+
*/
500+
external increment: t => unit = "%incr"
501+
502+
/**
503+
`decrement(intRef)` decrements the value of the provided reference by 1.
504+
505+
## Examples
506+
507+
```rescript
508+
let myRef = ref(4)
509+
Int.Ref.decrement(myRef)
510+
assertEqual(myRef.contents, 3)
511+
```
512+
*/
513+
external decrement: t => unit = "%decr"
514+
}

0 commit comments

Comments
 (0)