| 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 /** | 5 /** |
| 6 * An indexed sequence of elements of the same type. | 6 * An indexed sequence of elements of the same type. |
| 7 * | 7 * |
| 8 * This is a primitive interface that any finite integer-indexable | 8 * This is a primitive interface that any finite integer-indexable |
| 9 * sequence can implement. | 9 * sequence can implement. |
| 10 * It is intended for data structures where access by index is | 10 * It is intended for data structures where access by index is |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } | 49 } |
| 50 | 50 |
| 51 reduce(initialValue, combine(previousValue, E element)) { | 51 reduce(initialValue, combine(previousValue, E element)) { |
| 52 var value = initialValue; | 52 var value = initialValue; |
| 53 for (int i = 0; i < this.length; i++) { | 53 for (int i = 0; i < this.length; i++) { |
| 54 value = combine(value, this[i]); | 54 value = combine(value, this[i]); |
| 55 } | 55 } |
| 56 return value; | 56 return value; |
| 57 } | 57 } |
| 58 | 58 |
| 59 Collection<E> where(bool f(E element)) { | 59 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); |
| 60 List<E> result = <E>[]; | |
| 61 for (int i = 0; i < this.length; i++) { | |
| 62 E element = this[i]; | |
| 63 if (f(element)) result.add(element); | |
| 64 } | |
| 65 return result; | |
| 66 } | |
| 67 | 60 |
| 68 bool every(bool f(E element)) { | 61 bool every(bool f(E element)) { |
| 69 for (int i = 0; i < this.length; i++) { | 62 for (int i = 0; i < this.length; i++) { |
| 70 if (!f(this[i])) return false; | 63 if (!f(this[i])) return false; |
| 71 } | 64 } |
| 72 return true; | 65 return true; |
| 73 } | 66 } |
| 74 | 67 |
| 75 bool some(bool f(E element)) { | 68 bool some(bool f(E element)) { |
| 76 for (int i = 0; i < this.length; i++) { | 69 for (int i = 0; i < this.length; i++) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 198 } |
| 206 E get current { | 199 E get current { |
| 207 if (0 <= _position && _position < _sequence.length) { | 200 if (0 <= _position && _position < _sequence.length) { |
| 208 return _sequence[_position]; | 201 return _sequence[_position]; |
| 209 } | 202 } |
| 210 // TODO(floitsch): adapt error-message. | 203 // TODO(floitsch): adapt error-message. |
| 211 throw new StateError("No more elements"); | 204 throw new StateError("No more elements"); |
| 212 } | 205 } |
| 213 } | 206 } |
| 214 | 207 |
| OLD | NEW |