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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 | 419 |
420 typedef bool _ElementPredicate<E>(E element); | 420 typedef bool _ElementPredicate<E>(E element); |
421 | 421 |
422 class WhereIterable<E> extends Iterable<E> { | 422 class WhereIterable<E> extends Iterable<E> { |
423 final Iterable<E> _iterable; | 423 final Iterable<E> _iterable; |
424 final _ElementPredicate<E> _f; | 424 final _ElementPredicate<E> _f; |
425 | 425 |
426 WhereIterable(this._iterable, bool this._f(E element)); | 426 WhereIterable(this._iterable, bool this._f(E element)); |
427 | 427 |
428 Iterator<E> get iterator => new WhereIterator<E>(_iterable.iterator, _f); | 428 Iterator<E> get iterator => new WhereIterator<E>(_iterable.iterator, _f); |
429 | |
430 // Specialization of [Iterable.map] to non-EfficientLength. | |
431 Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(E element)) => | |
432 new MappedIterable<E, dynamic/*=T*/>._(this, f); | |
Lasse Reichstein Nielsen
2016/09/21 07:17:13
I don't see why this makes any difference - the me
sra1
2016/09/21 16:26:22
The difference is
new MappedIterable<E, T>(this, f
Lasse Reichstein Nielsen
2016/09/21 19:42:16
Ah, I completely missed that difference :)
| |
429 } | 433 } |
430 | 434 |
431 class WhereIterator<E> extends Iterator<E> { | 435 class WhereIterator<E> extends Iterator<E> { |
432 final Iterator<E> _iterator; | 436 final Iterator<E> _iterator; |
433 final _ElementPredicate _f; | 437 final _ElementPredicate _f; |
434 | 438 |
435 WhereIterator(this._iterator, bool this._f(E element)); | 439 WhereIterator(this._iterator, bool this._f(E element)); |
436 | 440 |
437 bool moveNext() { | 441 bool moveNext() { |
438 while (_iterator.moveNext()) { | 442 while (_iterator.moveNext()) { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 * Creates errors throw by [Iterable] when the element count is wrong. | 762 * Creates errors throw by [Iterable] when the element count is wrong. |
759 */ | 763 */ |
760 abstract class IterableElementError { | 764 abstract class IterableElementError { |
761 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */ | 765 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */ |
762 static StateError noElement() => new StateError("No element"); | 766 static StateError noElement() => new StateError("No element"); |
763 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */ | 767 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */ |
764 static StateError tooMany() => new StateError("Too many elements"); | 768 static StateError tooMany() => new StateError("Too many elements"); |
765 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */ | 769 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */ |
766 static StateError tooFew() => new StateError("Too few elements"); | 770 static StateError tooFew() => new StateError("Too few elements"); |
767 } | 771 } |
OLD | NEW |