-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add Iterable.fromIterator
(or similar, name less important)
#55961
Comments
As you noticed, its more like abstract class Iterator<T> {
// ...
Iterator.fromIteratorFactory(Iterator<T> Function() makeIterator) = _IterableFromIteratorFunction<T>;
// ...
}
final class _IterableFromIteratorFactory<T> extends Iterable<T> {
final Iterator<T> Function() _makeIterator;
IterableFromIteratorFactory(this._makeIterator);
Iterator<T> get iterator => _makeIterator();
} Not unreasonable. The reason I would very rarely use such a class is that I'd want to optimize some of the |
Do you have a concrete example you can link to? If Would iterable generator expressions solve your use case? dart-lang/language#1633 I do think this is worth adding. I hope we can find a shorter name than |
Hey @natebosch, @lrhn, I'm working on this, please assign this issue to me, I've submitted an initial pr #59908, there we can discuss if any changes are needed or if any additional test cases I need to cover |
Code looks fine at a first glance. Maybe just (I wish Dart had anonymous classes like Java, so you could just do new Iterable{get iterator {…}} rather than having to have all these "from functions" constructors.) |
Yeah, I couldn't find a better name for this I think |
Most of the time when creating a custom
Iterator
, the following pattern is followed:While I can imagine this is useful for optimizations, it's boiler-plate for getting started.
I'd love to see the following factory method added:
That would mean being able to just write:
It's a relatively small improvement, but it also is a relatively small enhancement :)
The text was updated successfully, but these errors were encountered: