Skip to content

Commit b5fecd4

Browse files
committed
add dict to the syntax widget
1 parent bdca716 commit b5fecd4

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

misc_docs/syntax/language_dict.mdx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
id: "dict"
3+
keywords: ["dict"]
4+
name: "dict"
5+
summary: "This is the `dict{}` syntax"
6+
category: "languageconstructs"
7+
---
8+
9+
> Available in v12+
10+
11+
The `dict{}` syntax is used to represent [dictionaries](dict.md). It's used both when creating dicts, and when pattern matching on dicts.
12+
13+
### Example
14+
15+
<CodeTab labels={["ReScript", "JS Output"]}>
16+
17+
```res
18+
// Create a dict
19+
let d = dict{"A": 5, "B": 6, "C": 7}
20+
21+
// Pattern match on the full dict
22+
let b = switch d {
23+
| dict{"B": b} => Some(b)
24+
| _ => None
25+
}
26+
27+
// Destructure the dict
28+
let dict{"C": ?c} = d
29+
```
30+
31+
```js
32+
let d = {
33+
A: 5,
34+
B: 6,
35+
C: 7
36+
};
37+
38+
let b = d.B;
39+
40+
let b$1 = b !== undefined ? b : undefined;
41+
42+
let c = d.C;
43+
```
44+
45+
</CodeTab>
46+
47+
### References
48+
49+
* [Dictionaries](/docs/manual/latest/dict)
50+
51+

0 commit comments

Comments
 (0)