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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/corelib/iterable_expand_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.collection; 5 part of dart.collection;
6 6
7 /** 7 /**
8 * Abstract implementation of a list. 8 * Abstract implementation of a list.
9 * 9 *
10 * All operations are defined in terms of `length`, `operator[]`, 10 * All operations are defined in terms of `length`, `operator[]`,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 167 }
168 } 168 }
169 return buffer.toString(); 169 return buffer.toString();
170 } 170 }
171 } 171 }
172 172
173 Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test); 173 Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test);
174 174
175 Iterable map(f(E element)) => new MappedListIterable(this, f); 175 Iterable map(f(E element)) => new MappedListIterable(this, f);
176 176
177 Iterable expand(Iterable f(E element)) =>
178 new ExpandIterable<E, dynamic>(this, f);
179
177 E reduce(E combine(E previousValue, E element)) { 180 E reduce(E combine(E previousValue, E element)) {
178 if (length == 0) throw new StateError("No elements"); 181 if (length == 0) throw new StateError("No elements");
179 E value = this[0]; 182 E value = this[0];
180 for (int i = 1; i < length; i++) { 183 for (int i = 1; i < length; i++) {
181 value = combine(value, this[i]); 184 value = combine(value, this[i]);
182 } 185 }
183 return value; 186 return value;
184 } 187 }
185 188
186 fold(var initialValue, combine(var previousValue, E element)) { 189 fold(var initialValue, combine(var previousValue, E element)) {
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 } 429 }
427 } 430 }
428 for (int i = startIndex; i >= 0; i--) { 431 for (int i = startIndex; i >= 0; i--) {
429 if (this[i] == element) { 432 if (this[i] == element) {
430 return i; 433 return i;
431 } 434 }
432 } 435 }
433 return -1; 436 return -1;
434 } 437 }
435 438
439 void insert(int index, E element) {
440 if (index < 0 || index > length) {
441 throw new RangeError.range(index, 0, length);
442 }
443 if (index == this.length) {
444 add(element);
445 return;
446 }
447 // We are modifying the length just below the is-check. Without the check
448 // Array.copy could throw an exception, leaving the list in a bad state
449 // (with a length that has been increased, but without a new element).
450 if (index is! int) throw new ArgumentError(index);
451 this.length++;
452 setRange(index + 1, this.length, this, index);
453 this[index] = element;
454 }
455
456 E removeAt(int index) {
457 E result = this[index];
458 setRange(index, this.length - 1, this, index + 1);
459 length--;
460 return result;
461 }
462
436 Iterable<E> get reversed => new ReversedListIterable(this); 463 Iterable<E> get reversed => new ReversedListIterable(this);
437 } 464 }
OLDNEW
« 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