Index: sdk/lib/html/html_common/filtered_element_list.dart |
diff --git a/sdk/lib/html/html_common/filtered_element_list.dart b/sdk/lib/html/html_common/filtered_element_list.dart |
index 7486555286c5d38d9363e8ab3ab6b3f2494dab5d..39a311c3b873de51e138a8c0c2e215aa204d1dcd 100644 |
--- a/sdk/lib/html/html_common/filtered_element_list.dart |
+++ b/sdk/lib/html/html_common/filtered_element_list.dart |
@@ -25,9 +25,10 @@ class FilteredElementList implements List { |
// We can't memoize this, since it's possible that children will be messed |
// with externally to this class. |
// |
- // TODO(nweiz): Do we really need to copy the list to make the types work out? |
+ // TODO(nweiz): we don't always need to create a new list. For example |
+ // forEach, every, any, ... could directly work on the _childNodes. |
List<Element> get _filtered => |
- new List.from(_childNodes.filter((n) => n is Element)); |
+ new List<Element>.from(_childNodes.where((n) => n is Element)); |
void forEach(void f(Element element)) { |
_filtered.forEach(f); |
@@ -48,12 +49,16 @@ class FilteredElementList implements List { |
removeRange(newLength, len - newLength); |
} |
+ String join([String separator]) => _filtered.join(separator); |
+ |
void add(Element value) { |
_childNodes.add(value); |
} |
- void addAll(Collection<Element> collection) { |
- collection.forEach(add); |
+ void addAll(Iterable<Element> iterable) { |
+ for (Element element in iterable) { |
+ add(element); |
+ } |
} |
void addLast(Element value) { |
@@ -94,6 +99,9 @@ class FilteredElementList implements List { |
return result; |
} |
+ Iterable mappedBy(f(Element element)) => _filtered.mappedBy(f); |
+ Iterable<Element> where(bool f(Element element)) => _filtered.where(f); |
+ |
Element removeAt(int index) { |
final result = this[index]; |
result.remove(); |
@@ -104,14 +112,29 @@ class FilteredElementList implements List { |
dynamic combine(dynamic previousValue, Element element)) { |
return Collections.reduce(this, initialValue, combine); |
} |
- Collection map(f(Element element)) => _filtered.map(f); |
- Collection<Element> filter(bool f(Element element)) => _filtered.filter(f); |
bool every(bool f(Element element)) => _filtered.every(f); |
- bool some(bool f(Element element)) => _filtered.some(f); |
+ bool any(bool f(Element element)) => _filtered.any(f); |
+ Element firstMatching(bool test(Element value), {Element orElse()}) { |
+ return _filtered.firstMatching(test, orElse: orElse); |
+ } |
+ |
+ Element lastMatching(bool test(Element value), {Element orElse()}) { |
+ return _filtered.lastMatching(test, orElse: orElse); |
+ } |
+ |
+ Element singleMatching(bool test(Element value)) { |
+ return _filtered.singleMatching(test); |
+ } |
+ |
+ E elementAt(int index) { |
+ return this[index]; |
+ } |
+ |
+ |
bool get isEmpty => _filtered.isEmpty; |
int get length => _filtered.length; |
Element operator [](int index) => _filtered[index]; |
- Iterator<Element> iterator() => _filtered.iterator(); |
+ Iterator<Element> get iterator => _filtered.iterator; |
List<Element> getRange(int start, int rangeLength) => |
_filtered.getRange(start, rangeLength); |
int indexOf(Element element, [int start = 0]) => |
@@ -122,7 +145,29 @@ class FilteredElementList implements List { |
return _filtered.lastIndexOf(element, start); |
} |
+ Iterable<Element> take(int n) { |
+ return new TakeIterable<Element>(this, n); |
+ } |
+ |
+ Iterable<Element> takeWhile(bool test(Element value)) { |
+ return new TakeWhileIterable<Element>(this, test); |
+ } |
+ |
+ Iterable<Element> skip(int n) { |
+ return new SkipIterable<Element>(this, n); |
+ } |
+ |
+ Iterable<Element> skipWhile(bool test(Element value)) { |
+ return new SkipWhileIterable<Element>(this, test); |
+ } |
+ |
Element get first => _filtered.first; |
Element get last => _filtered.last; |
+ |
+ Element get single => _filtered.single; |
+ |
+ Element min([int compare(Element a, Element b)]) => _filtered.min(compare); |
+ |
+ Element max([int compare(Element a, Element b)]) => _filtered.max(compare); |
} |