@@ -73,6 +73,28 @@ let isPet = (animal: animals) => {
73
73
74
74
Read more about [ variant type spreads in pattern matching] ( pattern-matching-destructuring.md#match-on-subtype-variants ) .
75
75
76
+ ## Polymorphic variant pattern matching
77
+ You can refine compatible polymorphic variants when pattern matching:
78
+
79
+ ``` res
80
+ type red = [#Ruby | #Redwood | #Rust]
81
+ type blue = [#Sapphire | #Neon | #Navy]
82
+
83
+ // Contains all constructors of red and blue.
84
+ // Also adds #Papayawhip
85
+ type color = [red | blue | #Papayawhip]
86
+
87
+ let myColor: color = #Ruby
88
+
89
+ switch myColor {
90
+ | #...blue => Console.log("This blue-ish")
91
+ | #...red => Console.log("This red-ish")
92
+ | other => Console.log2("Other color than red and blue: ", other)
93
+ }
94
+ ```
95
+
96
+ Read more about [ pattern matching and polymorphic variants] ( polymorphic-variant.md#combine-types-and-pattern-match ) .
97
+
76
98
## List immutable update
77
99
Spreads can be used for immutable updates of lists:
78
100
@@ -133,6 +155,7 @@ Read more about [partial application of functions](function.md#partial-applicati
133
155
* [ Record immutable updates] ( record.md#immutable-update )
134
156
* [ Variant type spreads] ( variant.md#variant-type-spreads )
135
157
* [ Variant type spreads in pattern matching] ( pattern-matching-destructuring.md#match-on-subtype-variants )
158
+ * [ Pattern matching and polymorphic variants] ( polymorphic-variant.md#combine-types-and-pattern-match )
136
159
* [ List immutable updates] ( array-and-list.md#immutable-prepend )
137
160
* [ List pattern matching] ( pattern-matching-destructuring.md#match-on-list )
138
161
* [ Array spreads] ( array-and-list.md#array-spreads )
0 commit comments