You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/docs/manual/v12.0.0/pattern-matching-destructuring.mdx
+5-4
Original file line number
Diff line number
Diff line change
@@ -479,7 +479,7 @@ if (person1.TAG) {
479
479
**Note:** Rescript versions < 9.0 had a `when` clause, not an `if` clause. Rescript 9.0 changed `when` to `if`. (`when` may still work, but is deprecated.)
480
480
481
481
### Match on subtype variants
482
-
You can refine a variant A to variant B using the variant type spread syntax in pattern matching. This is possible if variant B is a subtype of variant A.
482
+
You can refine a variant A to variant B using the [variant type spread syntax](variant.md#variant-type-spreads) in pattern matching. This is possible if variant B [is a subtype of](variant.md#coercion) variant A.
483
483
484
484
Let's look at an example:
485
485
@@ -549,7 +549,7 @@ Let's break down what we did:
549
549
550
550
Notice how we're able to match on parts of the main variant, as long as the variants are compatible.
551
551
552
-
The example above aliases the variant type spread to a variable so we can use it in our branch. But, you can just as easily match without aliasing if you don't care about the actual value for your branch:
552
+
The example above aliases the variant type spread to a variable so we can use it in our branch. But, you can just as easily match without aliasing if you don't care about the value:
553
553
<CodeTablabels={["ReScript", "JS Output"]}>
554
554
555
555
```res
@@ -577,7 +577,7 @@ function isPet(animal) {
577
577
```
578
578
</CodeTab>
579
579
580
-
Similarily, if you want to get really advanced, you can even pull out a single variant constructor. This works with and without aliases. Example:
580
+
Similarily, if you want to get advanced, you can even pull out a single variant constructor. This works with and without aliases. Example:
581
581
582
582
<CodeTablabels={["ReScript", "JS Output"]}>
583
583
@@ -615,7 +615,8 @@ type pets = Cat | Dog
615
615
type fish = Cod | Salmon
616
616
type animals = | ...pets | ...fish
617
617
618
-
// Notice `dog` isn't spread into the `pets` variant, but this still work due to subtyping
618
+
// Notice `dog` isn't spread into the `pets` variant,
0 commit comments