Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Unified Diff: sdk/lib/core/sequences.dart

Issue 11410086: Use iterator, moveNext(), current. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/core/sequences.dart
diff --git a/sdk/lib/core/sequences.dart b/sdk/lib/core/sequences.dart
index 32a3b4088ef23cea008323f4662884c5b151a635..5a0af69405def37a61b485747e3baf2f340cd0e1 100644
--- a/sdk/lib/core/sequences.dart
+++ b/sdk/lib/core/sequences.dart
@@ -33,7 +33,7 @@ abstract class Sequence<T> {
abstract class SequenceCollection<E> implements Collection<E>, Sequence<E> {
// The class is intended for use as a mixin as well.
- Iterator<E> iterator() => new SequenceIterator(sequence);
+ Iterator<E> get iterator => new SequenceIterator(sequence);
void forEach(f(E element)) {
for (int i = 0; i < this.length; i++) f(this[i]);
@@ -194,10 +194,18 @@ class SequenceList<E> extends SequenceCollection<E> implements List<E> {
class SequenceIterator<E> implements Iterator<E> {
Sequence<E> _sequence;
int _position;
- SequenceIterator(this._sequence) : _position = 0;
- bool get hasNext => _position < _sequence.length;
- E next() {
- if (hasNext) return _sequence[_position++];
+ SequenceIterator(this._sequence) : _position = -1;
+ bool moveNext() {
+ _position++;
+ if (_position < _sequence.length) return true;
+ _position = _sequence.length;
+ return false;
+ }
+ E get current {
+ if (0 <= _position && _position < _sequence.length) {
+ return _sequence[_position];
+ }
+ // TODO(floitsch): adapt error-message.
throw new StateError("No more elements");
}
}

Powered by Google App Engine
This is Rietveld 408576698