-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Fixes #9230. Context in that issue. See [code-level comments and stacked commits on the PR](#9232). ## Changes This PR is mostly additive, but there are some change. At least one is breaking. ### Iterators - `Iterator` is now a class representing the built-in, instead of a type representing an `IterableIterator` protocol. - This is the breaking change. Places that were using `Iterator` to represent the protocol need to do one of: - Switch to `$IteratorProtocol` to continue accepting custom implementations. - Wrap value with `Iterator.from` to get `Iterator`s. - The class now has three generic args, like `$Iterator`, but supplies defaults for the last two for backwards compatibility and simple uses. - `$Iterator` is now a type alias for this class. It can likely be deprecated and removed. - `$IteratorProtocol` is comparable to the old `$Iterator`, but does not require implementors to also implement `$Iterable` so that it imposes no extra constraints on `Iterator.from`. ### Iterables - `Iterable` and `$Iterable` now only constrain `@iterator` to `$IteratorProtocol`. The return value does not need to be iterable. Note that `Iterator.@iterator` returns an `Iterator` which is implements both the iterable and iterator protocols. ### Generators - `Generator` is now a type alias for a subclass of `Iterator`, rather than an interface. I [don't believe it's possible to implement a custom Generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator#constructor) so I believe this is correct. ## Consistency I prioritized minimizing changes over internal consistency with this PR. One path back to consistency: - Rename `$Iterable` to `$IterableProtocol` for consistency with `$IteratorProtocol` (optionally remove the $ prefix from both). - Remove `$Iterator`. This would have to be gradual migrations. Pull Request resolved: #9232 Test Plan: $ make && bash runtests.sh bin/flow Reviewed By: SamChou19815 Differential Revision: D66393981 fbshipit-source-id: 290fc3850d27c351f419363039b141f37a4174f6
- Loading branch information
1 parent
28adc18
commit 68da336
Showing
46 changed files
with
589 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.