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

Unified Diff: sdk/lib/_internal/compiler/implementation/tree/nodes.dart

Issue 11363252: Extend Iterable instead of implementing it. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Fix bad copy/paste. 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/_internal/compiler/implementation/tree/nodes.dart
diff --git a/sdk/lib/_internal/compiler/implementation/tree/nodes.dart b/sdk/lib/_internal/compiler/implementation/tree/nodes.dart
index 99d3a88876f3758fd7586a1f1e29827a5afd3189..ae8d9b43d6547d92d330325810f60e35cdc27cbf 100644
--- a/sdk/lib/_internal/compiler/implementation/tree/nodes.dart
+++ b/sdk/lib/_internal/compiler/implementation/tree/nodes.dart
@@ -466,6 +466,54 @@ class NodeList extends Node implements Iterable<Node> {
}
return beginToken;
}
+
+ // ------------------- Iterable methods -------------------------------------
+ //
+ // TODO(floitsch): these functions should be pulled in through a mixin
+ // mechanism.
+ Collection mappedBy(f(Node element)) {
+ List result = new List();
sra1 2012/11/15 01:02:18 new List() -> []
floitsch 2012/11/15 01:27:27 Done.
+ for (Node element in this) result.add(f(element));
+ return result;
+ }
+
+ Collection<Node> where(bool f(Node element)) {
+ List result = new List<Node>();
+ for (Node element in this) if (f(element)) result.add(element);
+ return result;
+ }
+
+ bool contains(Node element) {
+ for (Node e in this) {
+ if (e == element) return true;
+ }
+ return false;
+ }
+
+ void forEach(void f(Node element)) {
+ for (Node element in this) f(element);
+ }
+
+ dynamic reduce(var initialValue,
+ dynamic combine(var previousValue, Node element)) {
+ var value = initialValue;
+ for (Node element in this) value = combine(value, element);
+ return value;
+ }
+
+ bool every(bool f(Node element)) {
+ for (Node element in this) {
+ if (!f(element)) return false;
+ }
+ return true;
+ }
+
+ bool some(bool f(Node element)) {
+ for (Node element in this) {
+ if (f(element)) return true;
+ }
+ return false;
+ }
}
class Block extends Statement {

Powered by Google App Engine
This is Rietveld 408576698