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 _f; | 375 final _Transformation<S, T> _f; |
376 | 376 |
377 MappedIterable(this._iterable, T this._f(S element)); | 377 MappedIterable(this._iterable, T this._f(S element)); |
378 | 378 |
379 Iterator<T> get iterator => new MappedIterator<S, T>(_iterable.iterator, _f); | 379 Iterator<T> get iterator => new MappedIterator<S, T>(_iterable.iterator, _f); |
380 | 380 |
381 // Length related functions are independent of the mapping. | 381 // Length related functions are independent of the mapping. |
382 int get length => _iterable.length; | 382 int get length => _iterable.length; |
383 bool get isEmpty => _iterable.isEmpty; | 383 bool get isEmpty => _iterable.isEmpty; |
384 } | 384 } |
385 | 385 |
386 class MappedIterator<S, T> extends Iterator<T> { | 386 class MappedIterator<S, T> extends Iterator<T> { |
387 T _current; | 387 T _current; |
388 final Iterator<S> _iterator; | 388 final Iterator<S> _iterator; |
389 final _Transformation _f; | 389 final _Transformation<S, T> _f; |
390 | 390 |
391 MappedIterator(this._iterator, T this._f(S element)); | 391 MappedIterator(this._iterator, T this._f(S element)); |
392 | 392 |
393 bool moveNext() { | 393 bool moveNext() { |
394 if (_iterator.moveNext()) { | 394 if (_iterator.moveNext()) { |
395 _current = _f(_iterator.current); | 395 _current = _f(_iterator.current); |
396 return true; | 396 return true; |
397 } else { | 397 } else { |
398 _current = null; | 398 _current = null; |
399 return false; | 399 return false; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 _hasSkipped = true; | 565 _hasSkipped = true; |
566 while (_iterator.moveNext()) { | 566 while (_iterator.moveNext()) { |
567 if (!_f(_iterator.current)) return true; | 567 if (!_f(_iterator.current)) return true; |
568 } | 568 } |
569 } | 569 } |
570 return _iterator.moveNext(); | 570 return _iterator.moveNext(); |
571 } | 571 } |
572 | 572 |
573 E get current => _iterator.current; | 573 E get current => _iterator.current; |
574 } | 574 } |
OLD | NEW |