@@ -17,7 +17,7 @@ Use `Dict.getUnsafe` only when you are sure the key exists (i.e. when iterating
17
17
18
18
## Examples
19
19
```rescript
20
- let dict = Dict.fromArray([( "key1", "value1"), ( "key2", "value2")])
20
+ let dict = dict{ "key1": "value1", "key2": "value2"}
21
21
let value = dict->Dict.getUnsafe("key1")
22
22
Console.log(value) // value1
23
23
```
@@ -30,7 +30,7 @@ Returns the value at the provided key, if it exists. Returns an option.
30
30
31
31
## Examples
32
32
```rescript
33
- let dict = Dict.fromArray([( "someKey", "someValue")])
33
+ let dict = dict{ "someKey": "someValue"}
34
34
35
35
switch dict->Dict.get("someKey") {
36
36
| None => Console.log("Nope, didn't have the key.")
@@ -59,7 +59,7 @@ external set: (dict<'a>, string, 'a) => unit = ""
59
59
60
60
## Examples
61
61
```rescript
62
- let dict = Dict.fromArray([( "someKey", "someValue")])
62
+ let dict = dict{ "someKey": "someValue"}
63
63
64
64
dict->Dict.delete("someKey")
65
65
```
@@ -189,7 +189,7 @@ external assign: (dict<'a>, dict<'a>) => dict<'a> = "Object.assign"
189
189
190
190
## Examples
191
191
```rescript
192
- let dict = Dict.fromArray([( "key1", "value1"), ( "key2", "value2")])
192
+ let dict = dict{ "key1": "value1", "key2": "value2"}
193
193
let dict2 = dict->Dict.copy
194
194
195
195
// Both log `["key1", "key2"]` here.
@@ -206,7 +206,7 @@ external copy: (@as(json`{}`) _, dict<'a>) => dict<'a> = "Object.assign"
206
206
207
207
## Examples
208
208
```rescript
209
- let dict = Dict.fromArray([( "key1", "value1"), ( "key2", "value2")])
209
+ let dict = dict{ "key1": "value1", "key2": "value2"}
210
210
211
211
dict->Dict.forEach(value => {
212
212
Console.log(value)
@@ -220,7 +220,7 @@ let forEach: (dict<'a>, 'a => unit) => unit
220
220
221
221
## Examples
222
222
```rescript
223
- let dict = Dict.fromArray([( "key1", "value1"), ( "key2", "value2")])
223
+ let dict = dict{ "key1": "value1", "key2": "value2"}
224
224
225
225
dict->Dict.forEachWithKey((value, key) => {
226
226
Console.log2(value, key)
@@ -235,10 +235,25 @@ let forEachWithKey: (dict<'a>, ('a, string) => unit) => unit
235
235
## Examples
236
236
237
237
```rescript
238
- let dict = Dict.fromArray([( "key1", 1), ( "key2", 2)])
238
+ let dict = dict{ "key1": 1, "key2": 2}
239
239
240
240
dict->Dict.mapValues(v => v + 10)->Dict.toArray // [("key1", 11), ("key2", 12)]
241
241
dict->Dict.mapValues(v => Int.toString(v))->Dict.toArray // [("key1", "1"), ("key2", "2")]
242
242
```
243
243
*/
244
244
let mapValues: (dict<'a>, 'a => 'b) => dict<'b>
245
+
246
+ /**
247
+ `has(dictionary, "key")` returns true if the "key" is present in the dictionary.
248
+
249
+ ## Examples
250
+
251
+ ```rescript
252
+ let dict = dict{"key1": Some(1), "key2": None}
253
+
254
+ dict->Dict.has("key1") // true
255
+ dict->Dict.has("key2") // true
256
+ dict->Dict.has("key3") // false
257
+ ```
258
+ */
259
+ let has: (dict<'a>, string) => bool
0 commit comments