Skip to content

Commit 23b2f10

Browse files
committed
Merge branch 'main' into add-examples-tests
2 parents f6bf7a7 + 9129456 commit 23b2f10

24 files changed

+251
-63
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Next version
44

5+
## 1.0.0
6+
7+
- Up ReScript dependency to 11+.
8+
- `JSON`, `Null` and `Nullable` untagged variants are now properly exposed.
9+
- BREAKING: Duplicated definition of `result` in `Result` module removed, as `result` is now a built in. Switch out any `Result.t` type annotations to point to the built in `result` instead.
10+
511
## 0.7.0
612

713
- Add `Dict.getUnsafe` https://github.com/rescript-association/rescript-core/pull/167

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ In ReScript 11, it is shipped as a separate npm package @rescript/core that is a
66

77
## Versioning
88

9-
- Versions `0.x` targets ReScript v10.1 and below.
9+
- Versions [`0.x`](https://github.com/rescript-association/rescript-core/tree/0.x) targets ReScript v10.1 and below.
1010
- Versions `1.x` targets ReScript v11 and above, and contains code that will not work with v10.1 and below.
1111

1212
## Background

package-lock.json

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rescript/core",
3-
"version": "0.7.0",
3+
"version": "1.0.0",
44
"scripts": {
55
"clean": "rescript clean",
66
"build": "rescript",
@@ -24,11 +24,10 @@
2424
"src/**/*.mjs"
2525
],
2626
"peerDependencies": {
27-
"rescript": "^10.1.0 || ^11.0.0"
27+
"rescript": ">=11.0.0 || ^11.1.0-rc.2"
2828
},
2929
"devDependencies": {
30-
"@babel/code-frame": "7.18.6",
31-
"@rescript/tools": "^0.5.0",
32-
"rescript": "^11.1.0-rc.2"
30+
"rescript": "11.1.0-rc.2",
31+
"@babel/code-frame": "7.18.6"
3332
}
3433
}

src/Core__JSON.res

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
type t = Js.Json.t
1+
@unboxed
2+
type rec t = Js.Json.t =
3+
| Boolean(bool)
4+
| @as(null) Null
5+
| String(string)
6+
| Number(float)
7+
| Object(Core__Dict.t<t>)
8+
| Array(array<t>)
29

310
@raises @val external parseExn: string => t = "JSON.parse"
411
@raises @val external parseExnWithReviver: (string, (string, t) => t) => t = "JSON.parse"

src/Core__JSON.resi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ Functions for interacting with JSON.
55
/**
66
A type representing a JSON object.
77
*/
8-
type t = Js.Json.t
8+
@unboxed
9+
type rec t = Js.Json.t =
10+
| Boolean(bool)
11+
| @as(null) Null
12+
| String(string)
13+
| Number(float)
14+
| Object(Core__Dict.t<t>)
15+
| Array(array<t>)
916

1017
/**
1118
`parseExn(string)`

src/Core__Null.res

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
type t<'a> = Js.Null.t<'a>
1+
@unboxed
2+
type t<'a> = Js.Null.t<'a> =
3+
| Value('a)
4+
| @as(null) Null
25

36
external asNullable: t<'a> => Core__Nullable.t<'a> = "%identity"
47

src/Core__Null.resi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ If you also need to cover `undefined`, check out `Nullable` instead.
77
/**
88
A type representing a value that can be either `'a` or `null`.
99
*/
10-
type t<'a> = Js.Null.t<'a>
10+
@unboxed
11+
type t<'a> = Js.Null.t<'a> =
12+
| Value('a)
13+
| @as(null) Null
1114

1215
/**
1316
Converts a `Null.t` into a `Nullable.t`.

src/Core__Nullable.res

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
type t<'a> = Js.Nullable.t<'a>
1+
type t<'a> = Js.Nullable.t<'a> =
2+
| Value('a)
3+
| @as(null) Null
4+
| @as(undefined) Undefined
25

36
external null: t<'a> = "#null"
47

src/Core__Nullable.resi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ Primarily useful when interoping with JavaScript when you don't know whether you
88
Type representing a nullable value.
99
A nullable value can be the value `'a`, `null` or `undefined`.
1010
*/
11-
type t<'a> = Js.Nullable.t<'a>
11+
@unboxed
12+
type t<'a> = Js.Nullable.t<'a> =
13+
| Value('a)
14+
| @as(null) Null
15+
| @as(undefined) Undefined
1216

1317
/**
1418
The value `null`.

src/Core__Promise.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
type t<+'a> = promise<'a>
22

33
@new
4-
external make: ((@uncurry 'a => unit, 'e => unit) => unit) => t<'a> = "Promise"
4+
external make: (('a => unit, 'e => unit) => unit) => t<'a> = "Promise"
55

66
@val @scope("Promise")
77
external resolve: 'a => t<'a> = "resolve"
88

9-
@send external then: (t<'a>, @uncurry 'a => t<'b>) => t<'b> = "then"
9+
@send external then: (t<'a>, 'a => t<'b>) => t<'b> = "then"
1010

1111
@send
12-
external thenResolve: (t<'a>, @uncurry 'a => 'b) => t<'b> = "then"
12+
external thenResolve: (t<'a>, 'a => 'b) => t<'b> = "then"
1313

1414
@send external finally: (t<'a>, unit => unit) => t<'a> = "finally"
1515

@@ -35,7 +35,7 @@ external all5: ((t<'a>, t<'b>, t<'c>, t<'d>, t<'e>)) => t<('a, 'b, 'c, 'd, 'e)>
3535
external all6: ((t<'a>, t<'b>, t<'c>, t<'d>, t<'e>, t<'f>)) => t<('a, 'b, 'c, 'd, 'e, 'f)> = "all"
3636

3737
@send
38-
external _catch: (t<'a>, @uncurry exn => t<'a>) => t<'a> = "catch"
38+
external _catch: (t<'a>, exn => t<'a>) => t<'a> = "catch"
3939

4040
let catch = (promise: promise<'a>, callback: exn => promise<'a>): promise<'a> => {
4141
_catch(promise, err => {

src/Core__Promise.resi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Promise.make((resolve, reject) => {
7373
```
7474
*/
7575
@new
76-
external make: ((@uncurry 'a => unit, 'e => unit) => unit) => t<'a> = "Promise"
76+
external make: (('a => unit, 'e => unit) => unit) => t<'a> = "Promise"
7777

7878
/**
7979
`catch(promise, errorCallback)` registers an exception handler in a promise chain.
@@ -139,7 +139,7 @@ Promise.resolve(5)
139139
```
140140
*/
141141
@send
142-
external then: (t<'a>, @uncurry 'a => t<'b>) => t<'b> = "then"
142+
external then: (t<'a>, 'a => t<'b>) => t<'b> = "then"
143143

144144
/**
145145
`thenResolve(promise, callback)` converts an encapsulated value of a promise
@@ -163,7 +163,7 @@ In case you want to return another promise in your `callback`, consider using
163163
`then` instead.
164164
*/
165165
@send
166-
external thenResolve: (t<'a>, @uncurry 'a => 'b) => t<'b> = "then"
166+
external thenResolve: (t<'a>, 'a => 'b) => t<'b> = "then"
167167

168168
/**
169169
`finally(promise, callback)` is used to execute a function that is called no

src/Core__Result.res

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2424

25-
type t<'a, 'b> = result<'a, 'b> = Ok('a) | Error('b)
26-
2725
let getExn = x =>
2826
switch x {
2927
| Ok(x) => x

src/Core__Result.resi

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@
3838
3939
```res example
4040
type responseError = NotAvailable | NotFound
41-
type queryResult = t<string, responseError>
41+
type queryResult = result<string, responseError>
4242
4343
let failQueryUser = (username: string): queryResult => {
4444
Error(NotAvailable)
4545
}
4646
```
4747
*/
48-
type t<'a, 'b> = result<'a, 'b> = Ok('a) | Error('b)
49-
5048
/**
5149
`getExn(res)`: when `res` is `Ok(n)`, returns `n` when `res` is `Error(m)`, raise an exception
5250
@@ -56,7 +54,7 @@ type t<'a, 'b> = result<'a, 'b> = Ok('a) | Error('b)
5654
Result.getExn(Result.Error("Invalid data")) /* raises exception */
5755
```
5856
*/
59-
let getExn: t<'a, 'b> => 'a
57+
let getExn: result<'a, 'b> => 'a
6058

6159
/**
6260
`mapOr(res, default, f)`: When res is `Ok(n)`, returns `f(n)`,
@@ -70,10 +68,10 @@ let getExn: t<'a, 'b> => 'a
7068
Result.mapOr(error, 0, (x) => x / 2) == 0
7169
```
7270
*/
73-
let mapOr: (t<'a, 'c>, 'b, 'a => 'b) => 'b
71+
let mapOr: (result<'a, 'c>, 'b, 'a => 'b) => 'b
7472

7573
@deprecated("Use mapOr instead")
76-
let mapWithDefault: (t<'a, 'c>, 'b, 'a => 'b) => 'b
74+
let mapWithDefault: (result<'a, 'c>, 'b, 'a => 'b) => 'b
7775

7876
/**
7977
`map(res, f)`: When res is `Ok(n)`, returns `Ok(f(n))`. Otherwise returns res
@@ -88,7 +86,7 @@ let mapWithDefault: (t<'a, 'c>, 'b, 'a => 'b) => 'b
8886
Result.map(Error("Invalid data"), f) == Error("Invalid data")
8987
```
9088
*/
91-
let map: (t<'a, 'c>, 'a => 'b) => t<'b, 'c>
89+
let map: (result<'a, 'c>, 'a => 'b) => result<'b, 'c>
9290

9391
/**
9492
`flatMap(res, f)`: When res is `Ok(n)`, returns `f(n)`. Otherwise, returns res
@@ -110,7 +108,7 @@ let map: (t<'a, 'c>, 'a => 'b) => t<'b, 'c>
110108
Result.flatMap(Error("Already bad"), recip) == Error("Already bad")
111109
```
112110
*/
113-
let flatMap: (t<'a, 'c>, 'a => t<'b, 'c>) => t<'b, 'c>
111+
let flatMap: (result<'a, 'c>, 'a => result<'b, 'c>) => result<'b, 'c>
114112

115113
/**
116114
`getOr(res, defaultValue)`: If `res` is `Ok(n)`, returns `n`,
@@ -122,22 +120,22 @@ let flatMap: (t<'a, 'c>, 'a => t<'b, 'c>) => t<'b, 'c>
122120
Result.getOr(Error("Invalid Data"), 0) == 0
123121
```
124122
*/
125-
let getOr: (t<'a, 'b>, 'a) => 'a
123+
let getOr: (result<'a, 'b>, 'a) => 'a
126124

127125
@deprecated("Use getOr instead")
128-
let getWithDefault: (t<'a, 'b>, 'a) => 'a
126+
let getWithDefault: (result<'a, 'b>, 'a) => 'a
129127

130128
/**
131129
`isOk(res)`: Returns `true` if `res` is of the form `Ok(n)`, `false` if it is
132130
the `Error(e)` variant.
133131
*/
134-
let isOk: t<'a, 'b> => bool
132+
let isOk: result<'a, 'b> => bool
135133

136134
/**
137135
`isError(res)`: Returns `true` if `res` is of the form `Error(e)`, `false` if
138136
it is the `Ok(n)` variant.
139137
*/
140-
let isError: t<'a, 'b> => bool
138+
let isError: result<'a, 'b> => bool
141139

142140
/**
143141
`equal(res1, res2, f)`: Determine if two `Result` variables are equal with
@@ -166,7 +164,7 @@ let isError: t<'a, 'b> => bool
166164
Result.equal(bad1, bad2, mod10equal) == true
167165
```
168166
*/
169-
let equal: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => bool) => bool
167+
let equal: (result<'a, 'c>, result<'b, 'd>, ('a, 'b) => bool) => bool
170168

171169
/**
172170
`compare(res1, res2, f)`: Compare two `Result` variables with respect to a
@@ -202,7 +200,7 @@ let equal: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => bool) => bool
202200
Result.compare(Error("x"), Error("y"), mod10cmp) == 0.
203201
```
204202
*/
205-
let compare: (t<'a, 'c>, t<'b, 'd>, ('a, 'b) => Core__Ordering.t) => Core__Ordering.t
203+
let compare: (result<'a, 'c>, result<'b, 'd>, ('a, 'b) => Core__Ordering.t) => Core__Ordering.t
206204

207205
/**
208206
`forEach(res, f)` runs the provided function `f` on the `Ok` value. If `res` is `Error`, nothing happens.
@@ -214,7 +212,7 @@ Result.forEach(Ok(3), Console.log) // Logs "3", returns ()
214212
Result.forEach(Error("x"), Console.log) // Does nothing, returns ()
215213
```
216214
*/
217-
let forEach: (t<'a, 'b>, 'a => unit) => unit
215+
let forEach: (result<'a, 'b>, 'a => unit) => unit
218216

219217
/**
220218
`mapError(r, f)` generates a new `result` by applying the function `f` to the `Error` value. If the source is `Ok`, return it as-is.

src/Core__String.res

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,35 +61,29 @@ type normalizeForm = [#NFC | #NFD | #NFKC | #NFKD]
6161
external unsafeReplaceRegExpBy0: (
6262
string,
6363
Core__RegExp.t,
64-
(@uncurry ~match: string, ~offset: int, ~input: string) => string,
64+
(~match: string, ~offset: int, ~input: string) => string,
6565
) => string = "replace"
6666

6767
@send
6868
external unsafeReplaceRegExpBy1: (
6969
string,
7070
Core__RegExp.t,
71-
(@uncurry ~match: string, ~group1: string, ~offset: int, ~input: string) => string,
71+
(~match: string, ~group1: string, ~offset: int, ~input: string) => string,
7272
) => string = "replace"
7373

7474
@send
7575
external unsafeReplaceRegExpBy2: (
7676
string,
7777
Core__RegExp.t,
78-
(
79-
@uncurry ~match: string,
80-
~group1: string,
81-
~group2: string,
82-
~offset: int,
83-
~input: string,
84-
) => string,
78+
(~match: string, ~group1: string, ~group2: string, ~offset: int, ~input: string) => string,
8579
) => string = "replace"
8680

8781
@send
8882
external unsafeReplaceRegExpBy3: (
8983
string,
9084
Core__RegExp.t,
9185
(
92-
@uncurry ~match: string,
86+
~match: string,
9387
~group1: string,
9488
~group2: string,
9589
~group3: string,

src/Core__String.resi

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ String.unsafeReplaceRegExpBy0(str, re, matchFn) == "bEAUtIfUl vOwEls"
579579
external unsafeReplaceRegExpBy0: (
580580
string,
581581
Core__RegExp.t,
582-
(@uncurry ~match: string, ~offset: int, ~input: string) => string,
582+
(~match: string, ~offset: int, ~input: string) => string,
583583
) => string = "replace"
584584

585585
/**
@@ -602,7 +602,7 @@ String.unsafeReplaceRegExpBy1(str, re, matchFn) == "Jony is 41"
602602
external unsafeReplaceRegExpBy1: (
603603
string,
604604
Core__RegExp.t,
605-
(@uncurry ~match: string, ~group1: string, ~offset: int, ~input: string) => string,
605+
(~match: string, ~group1: string, ~offset: int, ~input: string) => string,
606606
) => string = "replace"
607607

608608
/**
@@ -628,13 +628,7 @@ String.unsafeReplaceRegExpBy2(str, re, matchFn) == "42"
628628
external unsafeReplaceRegExpBy2: (
629629
string,
630630
Core__RegExp.t,
631-
(
632-
@uncurry ~match: string,
633-
~group1: string,
634-
~group2: string,
635-
~offset: int,
636-
~input: string,
637-
) => string,
631+
(~match: string, ~group1: string, ~group2: string, ~offset: int, ~input: string) => string,
638632
) => string = "replace"
639633

640634
/**
@@ -647,7 +641,7 @@ external unsafeReplaceRegExpBy3: (
647641
string,
648642
Core__RegExp.t,
649643
(
650-
@uncurry ~match: string,
644+
~match: string,
651645
~group1: string,
652646
~group2: string,
653647
~group3: string,

0 commit comments

Comments
 (0)