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

Side by Side Diff: sdk/lib/collection/iterable.dart

Issue 14246008: Allow Object when doing lookups. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix type error. Created 7 years, 6 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 * This [Iterable] mixin implements all [Iterable] members except `iterator`. 8 * This [Iterable] mixin implements all [Iterable] members except `iterator`.
9 * 9 *
10 * All other methods are implemented in terms of `iterator`. 10 * All other methods are implemented in terms of `iterator`.
11 */ 11 */
12 abstract class IterableMixin<E> implements Iterable<E> { 12 abstract class IterableMixin<E> implements Iterable<E> {
13 Iterable map(f(E element)) => new MappedIterable<E, dynamic>(this, f); 13 Iterable map(f(E element)) => new MappedIterable<E, dynamic>(this, f);
14 14
15 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); 15 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f);
16 16
17 Iterable expand(Iterable f(E element)) => 17 Iterable expand(Iterable f(E element)) =>
18 new ExpandIterable<E, dynamic>(this, f); 18 new ExpandIterable<E, dynamic>(this, f);
19 19
20 bool contains(E element) { 20 bool contains(Object element) {
21 for (E e in this) { 21 for (E e in this) {
22 if (e == element) return true; 22 if (e == element) return true;
23 } 23 }
24 return false; 24 return false;
25 } 25 }
26 26
27 void forEach(void f(E element)) { 27 void forEach(void f(E element)) {
28 for (E element in this) f(element); 28 for (E element in this) f(element);
29 } 29 }
30 30
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // to combine const constructors and mixins. 204 // to combine const constructors and mixins.
205 const IterableBase(); 205 const IterableBase();
206 206
207 Iterable map(f(E element)) => new MappedIterable<E, dynamic>(this, f); 207 Iterable map(f(E element)) => new MappedIterable<E, dynamic>(this, f);
208 208
209 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); 209 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f);
210 210
211 Iterable expand(Iterable f(E element)) => 211 Iterable expand(Iterable f(E element)) =>
212 new ExpandIterable<E, dynamic>(this, f); 212 new ExpandIterable<E, dynamic>(this, f);
213 213
214 bool contains(E element) { 214 bool contains(Object element) {
215 for (E e in this) { 215 for (E e in this) {
216 if (e == element) return true; 216 if (e == element) return true;
217 } 217 }
218 return false; 218 return false;
219 } 219 }
220 220
221 void forEach(void f(E element)) { 221 void forEach(void f(E element)) {
222 for (E element in this) f(element); 222 for (E element in this) f(element);
223 } 223 }
224 224
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 E elementAt(int index) { 379 E elementAt(int index) {
380 if (index is! int || index < 0) throw new RangeError.value(index); 380 if (index is! int || index < 0) throw new RangeError.value(index);
381 int remaining = index; 381 int remaining = index;
382 for (E element in this) { 382 for (E element in this) {
383 if (remaining == 0) return element; 383 if (remaining == 0) return element;
384 remaining--; 384 remaining--;
385 } 385 }
386 throw new RangeError.value(index); 386 throw new RangeError.value(index);
387 } 387 }
388 } 388 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698