| 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.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The [Iterable] interface allows to get an [Iterator] out of an | 8 * The [Iterable] interface allows to get an [Iterator] out of an |
| 9 * [Iterable] object. | 9 * [Iterable] object. |
| 10 * | 10 * |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 remaining--; | 365 remaining--; |
| 366 } | 366 } |
| 367 throw new RangeError.value(index); | 367 throw new RangeError.value(index); |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 | 370 |
| 371 typedef T _Transformation<S, T>(S value); | 371 typedef T _Transformation<S, T>(S value); |
| 372 | 372 |
| 373 class MappedIterable<S, T> extends Iterable<T> { | 373 class MappedIterable<S, T> extends Iterable<T> { |
| 374 final Iterable<S> _iterable; | 374 final Iterable<S> _iterable; |
| 375 final _Transformation<S, T> _f; | 375 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 376 // checked mode. |
| 377 final /* _Transformation<S, T> */ _f; |
| 376 | 378 |
| 377 MappedIterable(this._iterable, T this._f(S element)); | 379 MappedIterable(this._iterable, T this._f(S element)); |
| 378 | 380 |
| 379 Iterator<T> get iterator => new MappedIterator<S, T>(_iterable.iterator, _f); | 381 Iterator<T> get iterator => new MappedIterator<S, T>(_iterable.iterator, _f); |
| 380 | 382 |
| 381 // Length related functions are independent of the mapping. | 383 // Length related functions are independent of the mapping. |
| 382 int get length => _iterable.length; | 384 int get length => _iterable.length; |
| 383 bool get isEmpty => _iterable.isEmpty; | 385 bool get isEmpty => _iterable.isEmpty; |
| 384 } | 386 } |
| 385 | 387 |
| 386 class MappedIterator<S, T> extends Iterator<T> { | 388 class MappedIterator<S, T> extends Iterator<T> { |
| 387 T _current; | 389 T _current; |
| 388 final Iterator<S> _iterator; | 390 final Iterator<S> _iterator; |
| 389 final _Transformation<S, T> _f; | 391 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 392 // checked mode. |
| 393 final /* _Transformation<S, T> */ _f; |
| 390 | 394 |
| 391 MappedIterator(this._iterator, T this._f(S element)); | 395 MappedIterator(this._iterator, T this._f(S element)); |
| 392 | 396 |
| 393 bool moveNext() { | 397 bool moveNext() { |
| 394 if (_iterator.moveNext()) { | 398 if (_iterator.moveNext()) { |
| 395 _current = _f(_iterator.current); | 399 _current = _f(_iterator.current); |
| 396 return true; | 400 return true; |
| 397 } else { | 401 } else { |
| 398 _current = null; | 402 _current = null; |
| 399 return false; | 403 return false; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 _hasSkipped = true; | 569 _hasSkipped = true; |
| 566 while (_iterator.moveNext()) { | 570 while (_iterator.moveNext()) { |
| 567 if (!_f(_iterator.current)) return true; | 571 if (!_f(_iterator.current)) return true; |
| 568 } | 572 } |
| 569 } | 573 } |
| 570 return _iterator.moveNext(); | 574 return _iterator.moveNext(); |
| 571 } | 575 } |
| 572 | 576 |
| 573 E get current => _iterator.current; | 577 E get current => _iterator.current; |
| 574 } | 578 } |
| OLD | NEW |