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

Unified Diff: sdk/lib/internal/iterable.dart

Issue 397243002: Make IterableMixinWorkaround using classes return correctly typed Iterables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment, Created 6 years, 5 months 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/collection/list.dart ('k') | sdk/lib/internal/list.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/internal/iterable.dart
diff --git a/sdk/lib/internal/iterable.dart b/sdk/lib/internal/iterable.dart
index 4cf841801a840490b88d5501340bac09ba45282f..006b31acb6fef4ee6860799d8135c2c10c6b1cfe 100644
--- a/sdk/lib/internal/iterable.dart
+++ b/sdk/lib/internal/iterable.dart
@@ -195,11 +195,11 @@ abstract class ListIterable<E> extends IterableBase<E>
return value;
}
- Iterable<E> skip(int count) => new SubListIterable(this, count, null);
+ Iterable<E> skip(int count) => new SubListIterable<E>(this, count, null);
Iterable<E> skipWhile(bool test(E element)) => super.skipWhile(test);
- Iterable<E> take(int count) => new SubListIterable(this, 0, count);
+ Iterable<E> take(int count) => new SubListIterable<E>(this, 0, count);
Iterable<E> takeWhile(bool test(E element)) => super.takeWhile(test);
@@ -276,17 +276,21 @@ class SubListIterable<E> extends ListIterable<E> {
Iterable<E> skip(int count) {
if (count < 0) throw new RangeError.value(count);
- return new SubListIterable(_iterable, _start + count, _endOrLength);
+ int newStart = _start + count;
+ if (_endOrLength != null && newStart >= _endOrLength) {
+ return new EmptyIterable<E>();
+ }
+ return new SubListIterable<E>(_iterable, newStart, _endOrLength);
}
Iterable<E> take(int count) {
if (count < 0) throw new RangeError.value(count);
if (_endOrLength == null) {
- return new SubListIterable(_iterable, _start, _start + count);
+ return new SubListIterable<E>(_iterable, _start, _start + count);
} else {
int newEnd = _start + count;
if (_endOrLength < newEnd) return this;
- return new SubListIterable(_iterable, _start, newEnd);
+ return new SubListIterable<E>(_iterable, _start, newEnd);
}
}
}
@@ -740,7 +744,7 @@ abstract class BidirectionalIterator<T> implements Iterator<T> {
*
* The uses of this class will be replaced by mixins.
*/
-class IterableMixinWorkaround {
+class IterableMixinWorkaround<T> {
static bool contains(Iterable iterable, var element) {
for (final e in iterable) {
if (e == element) return true;
@@ -934,8 +938,8 @@ class IterableMixinWorkaround {
return buffer.toString();
}
- static Iterable where(Iterable iterable, bool f(var element)) {
- return new WhereIterable(iterable, f);
+ Iterable<T> where(Iterable iterable, bool f(var element)) {
+ return new WhereIterable<T>(iterable, f);
}
static Iterable map(Iterable iterable, f(var element)) {
@@ -950,28 +954,28 @@ class IterableMixinWorkaround {
return new ExpandIterable(iterable, f);
}
- static Iterable takeList(List list, int n) {
+ Iterable<T> takeList(List list, int n) {
// The generic type is currently lost. It will be fixed with mixins.
- return new SubListIterable(list, 0, n);
+ return new SubListIterable<T>(list, 0, n);
}
- static Iterable takeWhile(Iterable iterable, bool test(var value)) {
+ Iterable<T> takeWhile(Iterable iterable, bool test(var value)) {
// The generic type is currently lost. It will be fixed with mixins.
- return new TakeWhileIterable(iterable, test);
+ return new TakeWhileIterable<T>(iterable, test);
}
- static Iterable skipList(List list, int n) {
+ Iterable<T> skipList(List list, int n) {
// The generic type is currently lost. It will be fixed with mixins.
- return new SubListIterable(list, n, null);
+ return new SubListIterable<T>(list, n, null);
}
- static Iterable skipWhile(Iterable iterable, bool test(var value)) {
+ Iterable<T> skipWhile(Iterable iterable, bool test(var value)) {
// The generic type is currently lost. It will be fixed with mixins.
- return new SkipWhileIterable(iterable, test);
+ return new SkipWhileIterable<T>(iterable, test);
}
- static Iterable reversedList(List list) {
- return new ReversedListIterable(list);
+ Iterable<T> reversedList(List list) {
+ return new ReversedListIterable<T>(list);
}
static void sortList(List list, int compare(a, b)) {
@@ -1009,10 +1013,10 @@ class IterableMixinWorkaround {
}
}
- static Iterable getRangeList(List list, int start, int end) {
+ Iterable<T> getRangeList(List list, int start, int end) {
_rangeCheck(list, start, end);
// The generic type is currently lost. It will be fixed with mixins.
- return new SubListIterable(list, start, end);
+ return new SubListIterable<T>(list, start, end);
}
static void setRangeList(List list, int start, int end,
@@ -1097,8 +1101,8 @@ class IterableMixinWorkaround {
}
}
- static Map<int, dynamic> asMapList(List l) {
- return new ListMapView(l);
+ Map<int, T> asMapList(List l) {
+ return new ListMapView<T>(l);
}
static bool setContainsAll(Set set, Iterable other) {
« no previous file with comments | « sdk/lib/collection/list.dart ('k') | sdk/lib/internal/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698