OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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._internal; | 5 part of dart._internal; |
6 | 6 |
7 /** | 7 /** |
8 * Marker interface for [Iterable] subclasses that have an efficient | 8 * Marker interface for [Iterable] subclasses that have an efficient |
9 * [length] implementation. | 9 * [length] implementation. |
10 */ | 10 */ |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 ListIterator(Iterable<E> iterable) | 311 ListIterator(Iterable<E> iterable) |
312 : _iterable = iterable, _length = iterable.length, _index = 0; | 312 : _iterable = iterable, _length = iterable.length, _index = 0; |
313 | 313 |
314 E get current => _current; | 314 E get current => _current; |
315 | 315 |
316 bool moveNext() { | 316 bool moveNext() { |
317 int length = _iterable.length; | 317 int length = _iterable.length; |
318 if (_length != length) { | 318 if (_length != length) { |
319 throw new ConcurrentModificationError(_iterable); | 319 throw new ConcurrentModificationError(_iterable); |
320 } | 320 } |
| 321 bool result = false; |
321 if (_index >= length) { | 322 if (_index >= length) { |
322 _current = null; | 323 _current = null; |
323 return false; | 324 } else { |
| 325 _current = _iterable.elementAt(_index); |
| 326 _index++; |
| 327 result = true; |
324 } | 328 } |
325 _current = _iterable.elementAt(_index); | 329 return result; |
326 _index++; | |
327 return true; | |
328 } | 330 } |
329 } | 331 } |
330 | 332 |
331 typedef T _Transformation<S, T>(S value); | 333 typedef T _Transformation<S, T>(S value); |
332 | 334 |
333 class MappedIterable<S, T> extends IterableBase<T> { | 335 class MappedIterable<S, T> extends IterableBase<T> { |
334 final Iterable<S> _iterable; | 336 final Iterable<S> _iterable; |
335 final _Transformation<S, T> _f; | 337 final _Transformation<S, T> _f; |
336 | 338 |
337 factory MappedIterable(Iterable iterable, T function(S value)) { | 339 factory MappedIterable(Iterable iterable, T function(S value)) { |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 * Creates errors throw by [Iterable] when the element count is wrong. | 1152 * Creates errors throw by [Iterable] when the element count is wrong. |
1151 */ | 1153 */ |
1152 abstract class IterableElementError { | 1154 abstract class IterableElementError { |
1153 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */ | 1155 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */ |
1154 static StateError noElement() => new StateError("No element"); | 1156 static StateError noElement() => new StateError("No element"); |
1155 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */ | 1157 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */ |
1156 static StateError tooMany() => new StateError("Too many elements"); | 1158 static StateError tooMany() => new StateError("Too many elements"); |
1157 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */ | 1159 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */ |
1158 static StateError tooFew() => new StateError("Too few elements"); | 1160 static StateError tooFew() => new StateError("Too few elements"); |
1159 } | 1161 } |
OLD | NEW |