Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CoreLib] Iterable.withIterator #59908

Closed

Conversation

drxddy
Copy link
Contributor

@drxddy drxddy commented Jan 14, 2025

Introduced a new factory constructor for Iterable class withIterator

Closes #55961

Usage

final numbers = Iterable.withIterator(() => [1, 2, 3].iterator);
print(numbers.toList()); // [1, 2, 3]
final numbers = [1, 2, 3];
final iterator = numbers.iterator;
iterator.moveNext();
var lazyIterable = Iterable.withIterator(() => iterator);

// Test that the first element is already consumed
var elements = lazyIterable.toList();  // [2, 3]
Expect.isNotEmpty(elements);
Expect.equals(2, elements.first);

Introduced a new factory constructor fromIteratorFactory to create an iterable from iterator
Copy link

Thank you for your contribution! This project uses Gerrit for code reviews. Your pull request has automatically been converted into a code review at:

https://dart-review.googlesource.com/c/sdk/+/404341

Please wait for a developer to review your code review at the above link; you can speed up the review if you sign into Gerrit and manually add a reviewer that has recently worked on the relevant code. See CONTRIBUTING.md to learn how to upload changes to Gerrit directly.

Additional commits pushed to this PR will update both the PR and the corresponding Gerrit CL. After the review is complete on the CL, your reviewer will merge the CL (automatically closing this PR).

Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

1 similar comment
Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

1 similar comment
Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

@drxddy drxddy changed the title [CoreLib] Iterable.fromIteratorFactory [CoreLib] Iterable.withIterator Jan 15, 2025
Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

@drxddy
Copy link
Contributor Author

drxddy commented Jan 15, 2025

@lrhn I've renamed it to Iterable.withIterator in this change fa07cf8, let me know if anything needs to be changed

Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

1 similar comment
Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

1 similar comment
Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

1 similar comment
Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

1 similar comment
Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

@drxddy
Copy link
Contributor Author

drxddy commented Jan 17, 2025

Hey, I've resolved all the changes suggested by @lrhn, please let me if anything can be better before we can merge it with main

Copy link
Member

@lrhn lrhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Small suggestions on the private class, nothing visible.

Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

1 similar comment
Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

@drxddy
Copy link
Contributor Author

drxddy commented Jan 17, 2025

Hi @lrhn, I've made these changes the latest commit 458904f

  • renamed the private class to _WithIteratorIterable
  • added doc comments explaining _WithIteratorIterable usage
  • changed parameter construction to this._iteratorFactory

Verified the SDK compilation on my local machine
Screenshot 2025-01-17 at 1 21 38 PM

Verified the newly added test was passing
Screenshot 2025-01-17 at 1 24 37 PM

Verified by running an example using the locally compiled SDK
Screenshot 2025-01-17 at 1 26 41 PM

Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

1 similar comment
Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

@drxddy
Copy link
Contributor Author

drxddy commented Jan 17, 2025

Hi @lrhn, I just made those white-space fixes and docs changes as you suggested in Gerrit, please merge if everything looks good.

Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

1 similar comment
Copy link

https://dart-review.googlesource.com/c/sdk/+/404341 has been updated with the latest commits from this pull request.

@drxddy
Copy link
Contributor Author

drxddy commented Jan 18, 2025

Hey @lrhn, I did dart format for the newly added test file to pass the pre-submit try test, I couldn't restart that failed test myself (access restricted), I'm curious to know when you added the CL to commit-queue, does it automatically kick-off all the relevant tests?

@lrhn
Copy link
Member

lrhn commented Jan 18, 2025

Yes, all I did was press the "commit" button. There is also a button to run tests without committing. The commit button only runs tests of the same patch hasn't already run the tests successfully.

@drxddy
Copy link
Contributor Author

drxddy commented Jan 19, 2025

Got it @lrhn, are there any changes I need to make or can we merge it?

@drxddy
Copy link
Contributor Author

drxddy commented Jan 21, 2025

Hey @lrhn, are there any changes required to merge this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Iterable.fromIterator (or similar, name less important)
2 participants