Chromium Code Reviews| Index: sdk/lib/core/iterable.dart |
| diff --git a/sdk/lib/core/iterable.dart b/sdk/lib/core/iterable.dart |
| index 06c8efa8b5f657b35e99ea0d8cc5fe306e986594..1213dcf68f05515287c6c24e7241fd4b70b8b0be 100644 |
| --- a/sdk/lib/core/iterable.dart |
| +++ b/sdk/lib/core/iterable.dart |
| @@ -35,22 +35,16 @@ abstract class Iterable<E> { |
| Iterable mappedBy(f(E element)) => new MappedIterable(this, f); |
| /** |
| - * Returns a collection with the elements of this collection |
| - * that satisfy the predicate [f]. |
| - * |
| - * The returned collection should be of the same type as the collection |
| - * creating it. |
| - * |
| - * An element satisfies the predicate [f] if [:f(element):] |
| - * returns true. |
| - */ |
| - Collection<E> where(bool f(E element)) { |
| - // TODO(floitsch): this is just a temporary function to provide a complete |
| - // skeleton. It will be changed to become lazy soon. |
| - List result = <E>[]; |
| - for (E element in this) if (f(element)) result.add(element); |
| - return result; |
| - } |
| + * Returns a lazy [Queryable] with all elements that satisfy the |
|
Anders Johnsen
2012/11/20 06:32:21
Queryable?
floitsch
2012/11/28 13:49:38
Done.
|
| + * predicate [f]. |
| + * |
| + * This method returns a view of the mapped elements. As long as the |
| + * returned [Queryable] is not iterated over, the supplied function [f] will |
| + * not be invoked. Iterating will not cache results, and thus iterating |
| + * multiple times over the the returned [Queryable] will invoke the supplied |
| + * function [f] multiple times on the same element. |
| + */ |
| + Iterable<E> where(bool f(E element)) => new FilteredIterable<E>(this, f); |
| /** |
| * Check whether the collection contains an element equal to [element]. |
| @@ -139,6 +133,10 @@ class MappedIterable<E> extends Iterable<E> { |
| MappedIterable(this._iterable, E this._f(element)); |
| Iterator<E> get iterator => new MappedIterator<E>(_iterable.iterator, _f); |
| + |
| + // Length related functions are independent of the mapping. |
| + int get length => _iterable.length; |
| + bool get isEmpty => _iterable.isEmpty; |
| } |
| class MappedIterator<E> extends Iterator<E> { |