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

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

Issue 11366111: Make Iterable more powerful (and lazy). (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Fix current. was in Iterable and not Iterator. 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
« no previous file with comments | « sdk/lib/core/iterable.dart ('k') | sdk/lib/core/list.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/iterator.dart
diff --git a/sdk/lib/core/iterator.dart b/sdk/lib/core/iterator.dart
index 2e324f6a9b26ead8b7d201a25dfc34f52855ebba..e6d7d0fb0321faaf2233229be83ddb1d85655ffd 100644
--- a/sdk/lib/core/iterator.dart
+++ b/sdk/lib/core/iterator.dart
@@ -9,16 +9,27 @@
*
* If the object iterated over is changed during the iteration, the
* behavior is unspecified.
+ *
+ * The [Iterator] is initially positioned before the first element. Before
+ * accessing the first element the iterator must thus be advanced ([moveNext])
+ * to point to the first element. If there is no element left, then [moveNext]
+ * returns false.
*/
abstract class Iterator<E> {
/**
- * Gets the next element in the iteration. Throws a
- * [StateError] if no element is left.
+ * Moves to the next element. Returns true if [current] contains the next
+ * element. Returns false, if no element was left. It the latter case
+ * trying to read [current] will throw a [StateError].
+ *
+ * It is safe to invoke [moveNext] even when the iterator is already
+ * positioned after the last element. In this case [moveNext] has no effect.
*/
- E next();
+ bool moveNext();
/**
- * Returns whether the [Iterator] has elements left.
+ * Returns the element the iterator is positioned at. This getter throws
+ * a [StateError] if the iterator is positioned before the first, or after the
+ * last element.
*/
- bool hasNext;
+ E get current;
}
« no previous file with comments | « sdk/lib/core/iterable.dart ('k') | sdk/lib/core/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698