Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 353a590135
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c225b3eaa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6bfdda1bde
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
joshderochervlk-simplisafe
left a comment
There was a problem hiding this comment.
The documentation looks good, and I like the way the usage looks in the examples.
There was a problem hiding this comment.
Is iterable the only thing we need to add to predefs? Is that enough to cover everything we need?
There was a problem hiding this comment.
For the for..of loop (upcoming PR), yes, but as there will also be the for await..of loop, we might as well add asyncIterable now, too.
zth
left a comment
There was a problem hiding this comment.
Haven't gotten into great depth because I don't know the subject too well, but looks good to me!
Introduce Explicit Iterator, Iterable, And Generator Types
Summary
This PR clarifies the stdlib iterator model so that it matches modern JavaScript more closely and gives each exposed module a distinct purpose.
This is a breaking change.
It is also a precondition for upcoming work on
for..ofloops.Motivation
Before this change, the sync iterator story blurred together several different runtime concepts:
Iterator.prototypeand has iterator helper methodsIn practice those are not the same thing.
For example:
next()is an iterator, but not iterablenext()and[Symbol.iterator]()is an iterable iterator, but it still may not have helper methods likemap()ortoArray()Array.values()andMap.entries()return built-in iterator objects that do have that helper-enabled runtime identity in modern runtimesThe goal of this PR is to make those differences visible in the API instead of implicitly treating them as one thing.
Type Guide
Overview
Iterable.t<'a>for..ofor consumed byArray.from.Iterator.t<'yield, 'return, 'next>next(), yielded values, final return values, and values passed back into iteration.IterableIterator.t<'yield, 'return, 'next>IteratorObject.t<'yield, 'return, 'next>Iterator.prototype, including iterator helper methods.Generator.t<'yield, 'return, 'next>AsyncIterable.t<'yield>for await..of.AsyncIterator.t<'yield, 'return, 'next>next(), yielded values, final return values, and values passed back into iteration.AsyncIterableIterator.t<'yield, 'return, 'next>AsyncGenerator.t<'yield, 'return, 'next>Breaking Changes In This PR
Stdlib.Iterator.tnow takes three type parametersStdlib.Iterator.tused to take one type parameter and now takes three:Iterator.t<'yield, 'return, 'next>The parameters mean:
'yield: the type produced while iterating'return: the final value when iteration completes'next: the type that can be passed back into iteration vianext(value)This matches the richer iterator model introduced in this PR and gives generators and protocol-level iterators a precise type for all three parts of the iteration protocol.
Raw iterator results are now normalized explicitly
JavaScript iterator results are slightly looser than the normalized model we want to expose in ReScript.
In particular, a yielded iterator result may omit
done, and that is still supposed to behave like a yield rather than completion.This PR therefore normalizes raw JavaScript iterator results before exposing them through
Iterator.resultandAsyncIterator.result.There is still a low-level raw representation for internal use and protocol-level interop, but it is not meant to be the main public story.
The important user-facing change is that
next()andnextValue()now behave correctly for protocol-compliant iterators even when yielded results omitdone.Built-in sync iterator APIs now return
IteratorObject.tThe following APIs are retargeted from protocol-only iterator types to
IteratorObject.t:Array.entriesArray.valuesMap.keysMap.valuesMap.entriesSet.valuesMotivation:
These are built-in iterator objects in modern runtimes, so the types should reflect the helper methods that are actually present.
Relationship To TypeScript
TypeScript distinguishes between:
IteratorIterableIterableIteratorIteratorObjectArrayIterator,MapIterator, andSetIteratorThis PR follows the same core distinction between protocol-only iterators and runtime-produced helper-enabled iterator objects, but deliberately does not expose TS-only specializations such as
ArrayIterator,MapIterator, orSetIterator.Docs
This PR also cleans up the
.residocs:IteratorObjectwhere appropriate