| OLD | NEW |
| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // to combine const constructors and mixins. | 202 // to combine const constructors and mixins. |
| 203 const IterableBase(); | 203 const IterableBase(); |
| 204 | 204 |
| 205 Iterable map(f(E element)) => new MappedIterable<E, dynamic>(this, f); | 205 Iterable map(f(E element)) => new MappedIterable<E, dynamic>(this, f); |
| 206 | 206 |
| 207 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); | 207 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); |
| 208 | 208 |
| 209 Iterable expand(Iterable f(E element)) => | 209 Iterable expand(Iterable f(E element)) => |
| 210 new ExpandIterable<E, dynamic>(this, f); | 210 new ExpandIterable<E, dynamic>(this, f); |
| 211 | 211 |
| 212 bool contains(E element) { | 212 bool contains(Object element) { |
| 213 for (E e in this) { | 213 for (E e in this) { |
| 214 if (e == element) return true; | 214 if (e == element) return true; |
| 215 } | 215 } |
| 216 return false; | 216 return false; |
| 217 } | 217 } |
| 218 | 218 |
| 219 void forEach(void f(E element)) { | 219 void forEach(void f(E element)) { |
| 220 for (E element in this) f(element); | 220 for (E element in this) f(element); |
| 221 } | 221 } |
| 222 | 222 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 E elementAt(int index) { | 375 E elementAt(int index) { |
| 376 if (index is! int || index < 0) throw new RangeError.value(index); | 376 if (index is! int || index < 0) throw new RangeError.value(index); |
| 377 int remaining = index; | 377 int remaining = index; |
| 378 for (E element in this) { | 378 for (E element in this) { |
| 379 if (remaining == 0) return element; | 379 if (remaining == 0) return element; |
| 380 remaining--; | 380 remaining--; |
| 381 } | 381 } |
| 382 throw new RangeError.value(index); | 382 throw new RangeError.value(index); |
| 383 } | 383 } |
| 384 } | 384 } |
| OLD | NEW |