Skip to content

Commit f1adede

Browse files
committed
when clause -> if clause
1 parent 1957356 commit f1adede

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pages/docs/manual/latest/pattern-matching-destructuring.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ if (typeof myStatus === "number" || myStatus.TAG) {
433433

434434
Slightly more verbose, but a one-time writing effort. This helps when you add a new variant case e.g. `Quarantined` to the `status` type and need to update the places that pattern match on it. A top-level wildcard here would have accidentally and silently continued working, potentially causing bugs.
435435

436-
### When Clause
436+
### If Clause
437437

438438
Sometime, you want to check more than the shape of a value. You want to also run some arbitrary check on it. You might be tempted to write this:
439439

@@ -469,7 +469,7 @@ if (person1.TAG) {
469469
```res example
470470
switch person1 {
471471
| Teacher(_) => () // do nothing
472-
| Student({reportCard: {gpa}}) when gpa < 0.5 =>
472+
| Student({reportCard: {gpa}}) if gpa < 0.5 =>
473473
Js.log("What's happening")
474474
| Student(_) =>
475475
// fall-through, catch-all case
@@ -488,6 +488,8 @@ if (person1.TAG) {
488488

489489
</CodeTab>
490490

491+
**Note:** In ReScript version < 9.0, the `if` clause is denoted as a `when`, but will be reformatted to `if` in newer versions.
492+
491493
### Match on Exceptions
492494

493495
If the function throws an exception (covered later), you can also match on _that_, in addition to the function's normally returned values.

0 commit comments

Comments
 (0)