Skip to content

Commit 2fd5c88

Browse files
committed
Remove Dict.t and use dict everywhere
1 parent 3b93359 commit 2fd5c88

File tree

36 files changed

+93
-100
lines changed

36 files changed

+93
-100
lines changed

runtime/Dict.res

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
type t<'a> = Js.Dict.t<'a>
2-
3-
@get_index external getUnsafe: (t<'a>, string) => 'a = ""
4-
@get_index external get: (t<'a>, string) => option<'a> = ""
5-
@set_index external set: (t<'a>, string, 'a) => unit = ""
1+
@get_index external getUnsafe: (dict<'a>, string) => 'a = ""
2+
@get_index external get: (dict<'a>, string) => option<'a> = ""
3+
@set_index external set: (dict<'a>, string, 'a) => unit = ""
64
@val external delete: 'a => unit = "delete"
75

86
let delete = (dict, string) => {
97
delete(get(dict, string))
108
}
119

12-
@obj external make: unit => t<'a> = ""
10+
@obj external make: unit => dict<'a> = ""
1311

14-
@val external fromArray: array<(string, 'a)> => t<'a> = "Object.fromEntries"
15-
@val external fromIterator: Iterator.t<(string, 'a)> => t<'a> = "Object.fromEntries"
12+
@val external fromArray: array<(string, 'a)> => dict<'a> = "Object.fromEntries"
13+
@val external fromIterator: Iterator.t<(string, 'a)> => dict<'a> = "Object.fromEntries"
1614

17-
@val external toArray: t<'a> => array<(string, 'a)> = "Object.entries"
15+
@val external toArray: dict<'a> => array<(string, 'a)> = "Object.entries"
1816

19-
@val external keysToArray: t<'a> => array<string> = "Object.keys"
17+
@val external keysToArray: dict<'a> => array<string> = "Object.keys"
2018

21-
@val external valuesToArray: t<'a> => array<'a> = "Object.values"
19+
@val external valuesToArray: dict<'a> => array<'a> = "Object.values"
2220

23-
@val external assign: (t<'a>, t<'a>) => t<'a> = "Object.assign"
21+
@val external assign: (dict<'a>, dict<'a>) => dict<'a> = "Object.assign"
2422

25-
@val external copy: (@as(json`{}`) _, t<'a>) => t<'a> = "Object.assign"
23+
@val external copy: (@as(json`{}`) _, dict<'a>) => dict<'a> = "Object.assign"
2624

2725
let forEach = (dict, f) => {
2826
dict->valuesToArray->Array.forEach(value => f(value))

runtime/Dict.resi

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ A mutable dictionary with string keys.
33
44
Compiles to a regular JavaScript object.*/
55

6-
/**
7-
Type representing a dictionary of value `'a`.
8-
*/
9-
type t<'a> = Js.Dict.t<'a>
10-
116
/**
127
`getUnsafe(dict, key)` Returns the `value` at the provided `key`.
138
@@ -23,7 +18,7 @@ Console.log(value) // value1
2318
```
2419
*/
2520
@get_index
26-
external getUnsafe: (t<'a>, string) => 'a = ""
21+
external getUnsafe: (dict<'a>, string) => 'a = ""
2722

2823
/**
2924
Returns the value at the provided key, if it exists. Returns an option.
@@ -39,7 +34,7 @@ switch dict->Dict.get("someKey") {
3934
```
4035
*/
4136
@get_index
42-
external get: (t<'a>, string) => option<'a> = ""
37+
external get: (dict<'a>, string) => option<'a> = ""
4338

4439
/**
4540
`set(dictionary, key, value)` sets the value at the provided key to the provided value.
@@ -52,7 +47,7 @@ dict->Dict.set("someKey", "someValue")
5247
```
5348
*/
5449
@set_index
55-
external set: (t<'a>, string, 'a) => unit = ""
50+
external set: (dict<'a>, string, 'a) => unit = ""
5651

5752
/**
5853
`delete(dictionary, key)` deletes the value at `key`, if it exists.
@@ -64,21 +59,21 @@ let dict = Dict.fromArray([("someKey", "someValue")])
6459
dict->Dict.delete("someKey")
6560
```
6661
*/
67-
let delete: (t<'a>, string) => unit
62+
let delete: (dict<'a>, string) => unit
6863

6964
/**
7065
`make()` creates a new, empty dictionary.
7166
7267
## Examples
7368
```rescript
74-
let dict1: Dict.t<int> = Dict.make() // You can annotate the type of the values of your dict yourself if you want
69+
let dict1: dict<int> = Dict.make() // You can annotate the type of the values of your dict yourself if you want
7570
7671
let dict2 = Dict.make() // Or you can let ReScript infer it via usage.
7772
dict2->Dict.set("someKey", 12)
7873
```
7974
*/
8075
@obj
81-
external make: unit => t<'a> = ""
76+
external make: unit => dict<'a> = ""
8277

8378
/**
8479
`fromArray(entries)` creates a new dictionary from the provided array of key/value pairs.
@@ -89,7 +84,7 @@ let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")])
8984
```
9085
*/
9186
@val
92-
external fromArray: array<(string, 'a)> => t<'a> = "Object.fromEntries"
87+
external fromArray: array<(string, 'a)> => dict<'a> = "Object.fromEntries"
9388

9489
/**
9590
`fromIterator(entries)` creates a new dictionary from the provided iterator of key/value pairs.
@@ -99,11 +94,11 @@ external fromArray: array<(string, 'a)> => t<'a> = "Object.fromEntries"
9994
// Pretend we have an iterator of the correct shape
10095
@val external someIterator: Iterator.t<(string, int)> = "someIterator"
10196
102-
let dict = Dict.fromIterator(someIterator) // Dict.t<int>
97+
let dict = Dict.fromIterator(someIterator) // dict<int>
10398
```
10499
*/
105100
@val
106-
external fromIterator: Iterator.t<(string, 'a)> => t<'a> = "Object.fromEntries"
101+
external fromIterator: Iterator.t<(string, 'a)> => dict<'a> = "Object.fromEntries"
107102

108103
/**
109104
`toArray(dictionary)` returns an array of all the key/value pairs of the dictionary.
@@ -118,7 +113,7 @@ Console.log(asArray) // Logs `[["someKey", 1], ["someKey2", 2]]` to the console
118113
```
119114
*/
120115
@val
121-
external toArray: t<'a> => array<(string, 'a)> = "Object.entries"
116+
external toArray: dict<'a> => array<(string, 'a)> = "Object.entries"
122117

123118
/**
124119
`keysToArray(dictionary)` returns an array of all the keys of the dictionary.
@@ -133,7 +128,7 @@ Console.log(keys) // Logs `["someKey", "someKey2"]` to the console
133128
```
134129
*/
135130
@val
136-
external keysToArray: t<'a> => array<string> = "Object.keys"
131+
external keysToArray: dict<'a> => array<string> = "Object.keys"
137132

138133
/**
139134
`valuesToArray(dictionary)` returns an array of all the values of the dictionary.
@@ -148,7 +143,7 @@ Console.log(values) // Logs `[1, 2]` to the console
148143
```
149144
*/
150145
@val
151-
external valuesToArray: t<'a> => array<'a> = "Object.values"
146+
external valuesToArray: dict<'a> => array<'a> = "Object.values"
152147

153148
/**
154149
`assign(dictionary1, dictionary2)` [shallowly](https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy) merges dictionary2 into dictionary1, and returns dictionary1.
@@ -172,7 +167,7 @@ Console.log(dict1->Dict.keysToArray) // Logs `["firstKey", "someKey", "someKey2"
172167
```
173168
*/
174169
@val
175-
external assign: (t<'a>, t<'a>) => t<'a> = "Object.assign"
170+
external assign: (dict<'a>, dict<'a>) => dict<'a> = "Object.assign"
176171

177172
/**
178173
`copy(dictionary)` [shallowly copies](https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy) the provided dictionary to a new dictionary.
@@ -187,7 +182,7 @@ Console.log2(dict->Dict.keysToArray, dict2->Dict.keysToArray)
187182
```
188183
*/
189184
@val
190-
external copy: (@as(json`{}`) _, t<'a>) => t<'a> = "Object.assign"
185+
external copy: (@as(json`{}`) _, dict<'a>) => dict<'a> = "Object.assign"
191186

192187
/**
193188
`forEach(dictionary, f)` iterates through all values of the dict.
@@ -203,7 +198,7 @@ dict->Dict.forEach(value => {
203198
})
204199
```
205200
*/
206-
let forEach: (t<'a>, 'a => unit) => unit
201+
let forEach: (dict<'a>, 'a => unit) => unit
207202

208203
/**
209204
`forEachWithKey(dictionary, f)` iterates through all values of the dict, including the key for each value.
@@ -217,7 +212,7 @@ dict->Dict.forEachWithKey((value, key) => {
217212
})
218213
```
219214
*/
220-
let forEachWithKey: (t<'a>, ('a, string) => unit) => unit
215+
let forEachWithKey: (dict<'a>, ('a, string) => unit) => unit
221216

222217
/**
223218
`mapValues(dictionary, f)` returns a new dictionary with the same keys, and `f` applied to each value in the original dictionary.
@@ -231,4 +226,4 @@ dict->Dict.mapValues(v => v + 10)->Dict.toArray // [("key1", 11), ("key2", 12)]
231226
dict->Dict.mapValues(v => Int.toString(v))->Dict.toArray // [("key1", "1"), ("key2", "2")]
232227
```
233228
*/
234-
let mapValues: (t<'a>, 'a => 'b) => t<'b>
229+
let mapValues: (dict<'a>, 'a => 'b) => dict<'b>

runtime/JSON.res

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type rec t = Js.Json.t =
44
| @as(null) Null
55
| String(string)
66
| Number(float)
7-
| Object(Dict.t<t>)
7+
| Object(dict<t>)
88
| Array(array<t>)
99

1010
@unboxed
@@ -47,15 +47,15 @@ module Classify = {
4747
| Null
4848
| String(string)
4949
| Number(float)
50-
| Object(Dict.t<t>)
50+
| Object(dict<t>)
5151
| Array(array<t>)
5252

5353
@val external _internalClass: 'a => string = "Object.prototype.toString.call"
5454
external _asBool: 'a => bool = "%identity"
5555
external _asString: 'a => string = "%identity"
5656
external _asFloat: 'a => float = "%identity"
5757
external _asArray: 'a => array<Js.Json.t> = "%identity"
58-
external _asDict: 'a => Dict.t<Js.Json.t> = "%identity"
58+
external _asDict: 'a => dict<Js.Json.t> = "%identity"
5959

6060
let classify = value => {
6161
switch _internalClass(value) {
@@ -75,7 +75,7 @@ module Encode = {
7575
external string: string => t = "%identity"
7676
external int: int => t = "%identity"
7777
external float: float => t = "%identity"
78-
external object: Dict.t<t> => t = "%identity"
78+
external object: dict<t> => t = "%identity"
7979
external array: array<t> => t = "%identity"
8080
}
8181

@@ -86,7 +86,7 @@ module Decode = {
8686
let float = (json: t) => Type.typeof(json) === #number ? Some((Obj.magic(json): float)) : None
8787
let object = (json: t) =>
8888
if Type.typeof(json) === #object && !Array.isArray(json) && !(Obj.magic(json) === Null.null) {
89-
Some((Obj.magic(json): Dict.t<t>))
89+
Some((Obj.magic(json): dict<t>))
9090
} else {
9191
None
9292
}

runtime/JSON.resi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type rec t = Js.Json.t =
1111
| @as(null) Null
1212
| String(string)
1313
| Number(float)
14-
| Object(Dict.t<t>)
14+
| Object(dict<t>)
1515
| Array(array<t>)
1616

1717
@unboxed
@@ -578,7 +578,7 @@ module Classify: {
578578
| Null
579579
| String(string)
580580
| Number(float)
581-
| Object(Dict.t<t>)
581+
| Object(dict<t>)
582582
| Array(array<t>)
583583

584584
/**
@@ -660,7 +660,7 @@ module Encode: {
660660
JSON.Encode.object(dict)
661661
```
662662
*/
663-
external object: Dict.t<t> => t = "%identity"
663+
external object: dict<t> => t = "%identity"
664664

665665
/**
666666
Returns an array as a JSON object.
@@ -733,7 +733,7 @@ module Decode: {
733733
let float: t => option<float>
734734

735735
/**
736-
Decodes a single JSON value. If the value is an object, it will return `Some(Dict.t)` - otherwise it will return `None`.
736+
Decodes a single JSON value. If the value is an object, it will return `Some(dict)` - otherwise it will return `None`.
737737
738738
## Examples
739739
```rescript
@@ -744,7 +744,7 @@ module Decode: {
744744
// None
745745
```
746746
*/
747-
let object: t => option<Dict.t<t>>
747+
let object: t => option<dict<t>>
748748

749749
/**
750750
Decodes a single JSON value. If the value is an array, it will return `Some(array)` - otherwise it will return `None`.

runtime/Js_json.res

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ type rec t =
3030
| @as(null) Null
3131
| String(string)
3232
| Number(float)
33-
| Object(Js_dict.t<t>)
33+
| Object(dict<t>)
3434
| Array(array<t>)
3535

3636
module Kind = {
3737
type json = t
3838
type rec t<_> =
3939
| String: t<Js_string.t>
4040
| Number: t<float>
41-
| Object: t<Js_dict.t<json>>
41+
| Object: t<dict<json>>
4242
| Array: t<array<json>>
4343
| Boolean: t<bool>
4444
| Null: t<Js_types.null_val>
@@ -50,7 +50,7 @@ type tagged_t =
5050
| JSONNull
5151
| JSONString(string)
5252
| JSONNumber(float)
53-
| JSONObject(Js_dict.t<t>)
53+
| JSONObject(dict<t>)
5454
| JSONArray(array<t>)
5555

5656
let classify = (x: t): tagged_t => {
@@ -105,7 +105,7 @@ let decodeObject = json =>
105105
(!Js_array2.isArray(json) &&
106106
!((Obj.magic(json): Js_null.t<'a>) === Js_extern.null))
107107
) {
108-
Some((Obj.magic((json: t)): Js_dict.t<t>))
108+
Some((Obj.magic((json: t)): dict<t>))
109109
} else {
110110
None
111111
}
@@ -143,15 +143,15 @@ let decodeNull = (json): option<Js_null.t<_>> =>
143143
external string: string => t = "%identity"
144144
external number: float => t = "%identity"
145145
external boolean: bool => t = "%identity"
146-
external object_: Js_dict.t<t> => t = "%identity"
146+
external object_: dict<t> => t = "%identity"
147147

148148
/* external array_ : t array -> t = "%identity" */
149149

150150
external array: array<t> => t = "%identity"
151151
external stringArray: array<string> => t = "%identity"
152152
external numberArray: array<float> => t = "%identity"
153153
external booleanArray: array<bool> => t = "%identity"
154-
external objectArray: array<Js_dict.t<t>> => t = "%identity"
154+
external objectArray: array<dict<t>> => t = "%identity"
155155
@val @scope("JSON") external stringify: t => string = "stringify"
156156
@val @scope("JSON") external stringifyWithSpace: (t, @as(json`null`) _, int) => string = "stringify"
157157

0 commit comments

Comments
 (0)