File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments