| 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 21 matching lines...) Expand all Loading... |
| 32 */ | 32 */ |
| 33 abstract class SequenceCollection<E> implements Collection<E>, Sequence<E> { | 33 abstract class SequenceCollection<E> implements Collection<E>, Sequence<E> { |
| 34 // The class is intended for use as a mixin as well. | 34 // The class is intended for use as a mixin as well. |
| 35 | 35 |
| 36 Iterator<E> get iterator => new SequenceIterator(sequence); | 36 Iterator<E> get iterator => new SequenceIterator(sequence); |
| 37 | 37 |
| 38 void forEach(f(E element)) { | 38 void forEach(f(E element)) { |
| 39 for (int i = 0; i < this.length; i++) f(this[i]); | 39 for (int i = 0; i < this.length; i++) f(this[i]); |
| 40 } | 40 } |
| 41 | 41 |
| 42 Collection mappedBy(f(E element)) { | 42 Iterable mappedBy(f(E element)) => new MappedIterable(this, f); |
| 43 List result = new List(); | |
| 44 for (int i = 0; i < this.length; i++) { | |
| 45 result.add(f(this[i])); | |
| 46 } | |
| 47 return result; | |
| 48 } | |
| 49 | 43 |
| 50 bool contains(E value) { | 44 bool contains(E value) { |
| 51 for (int i = 0; i < sequence.length; i++) { | 45 for (int i = 0; i < sequence.length; i++) { |
| 52 if (sequence[i] == value) return true; | 46 if (sequence[i] == value) return true; |
| 53 } | 47 } |
| 54 return false; | 48 return false; |
| 55 } | 49 } |
| 56 | 50 |
| 57 reduce(initialValue, combine(previousValue, E element)) { | 51 reduce(initialValue, combine(previousValue, E element)) { |
| 58 var value = initialValue; | 52 var value = initialValue; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 } | 205 } |
| 212 E get current { | 206 E get current { |
| 213 if (0 <= _position && _position < _sequence.length) { | 207 if (0 <= _position && _position < _sequence.length) { |
| 214 return _sequence[_position]; | 208 return _sequence[_position]; |
| 215 } | 209 } |
| 216 // TODO(floitsch): adapt error-message. | 210 // TODO(floitsch): adapt error-message. |
| 217 throw new StateError("No more elements"); | 211 throw new StateError("No more elements"); |
| 218 } | 212 } |
| 219 } | 213 } |
| 220 | 214 |
| OLD | NEW |