Skip to content

Commit 4d097c3

Browse files
committed
Add a note about pattern matching iterables. Closes tc39#4.
1 parent 2c696de commit 4d097c3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ match (arr) {
8686
}
8787
```
8888

89+
It is possible that array patterns could also match iterables, however it's not clear this design is desirable. First, it's not clear that users of pattern matching would expect array patterns to match any object with Symbol.iterable. Second, since pulling values out of an iterable is side-effecty, it introduces a lot of confusion around what the state of the iterable is in each match leg and it's not clear that side-effecty-by-default pattern matching is a good idea.
90+
91+
That said, destructuring does work on iterables so there is a strong alignment argument here.
92+
8993
## Literal Patterns
9094
Literal patterns are string, number, boolean, null, and undefined literals and matches exactly that value. Examples:
9195

0 commit comments

Comments
 (0)