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

Unified Diff: sdk/lib/collection/list.dart

Issue 13877006: Add missing functions to ListMixin. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 | « no previous file | tests/corelib/iterable_expand_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/list.dart
diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart
index 00ccd09c9fb5e58a7c3557920eb761b0d7e29e35..0ceb70bbf8ca18a4a53484d97bc5ba420b15461a 100644
--- a/sdk/lib/collection/list.dart
+++ b/sdk/lib/collection/list.dart
@@ -174,6 +174,9 @@ abstract class ListMixin<E> implements List<E> {
Iterable map(f(E element)) => new MappedListIterable(this, f);
+ Iterable expand(Iterable f(E element)) =>
+ new ExpandIterable<E, dynamic>(this, f);
+
E reduce(E combine(E previousValue, E element)) {
if (length == 0) throw new StateError("No elements");
E value = this[0];
@@ -433,5 +436,29 @@ abstract class ListMixin<E> implements List<E> {
return -1;
}
+ void insert(int index, E element) {
+ if (index < 0 || index > length) {
+ throw new RangeError.range(index, 0, length);
+ }
+ if (index == this.length) {
+ add(element);
+ return;
+ }
+ // We are modifying the length just below the is-check. Without the check
+ // Array.copy could throw an exception, leaving the list in a bad state
+ // (with a length that has been increased, but without a new element).
+ if (index is! int) throw new ArgumentError(index);
+ this.length++;
+ setRange(index + 1, this.length, this, index);
+ this[index] = element;
+ }
+
+ E removeAt(int index) {
+ E result = this[index];
+ setRange(index, this.length - 1, this, index + 1);
+ length--;
+ return result;
+ }
+
Iterable<E> get reversed => new ReversedListIterable(this);
}
« no previous file with comments | « no previous file | tests/corelib/iterable_expand_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698