| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 /** |
| 6 * The [Queryable] interface extends the [Iterable] interface and adds |
| 7 * functionality that can be expressed with iterators but does not necessarily |
| 8 * make sense on collections that implement [Iterable]. |
| 9 */ |
| 10 abstract class Queryable<E> extends Iterable<E> { |
| 11 /** |
| 12 * Returns a lazy [Queryable] with at most [count] elements. |
| 13 * |
| 14 * If [this] produces less than [count] elements, then the resulting |
| 15 * [Queryable] will produce less than [count] elements, too. |
| 16 */ |
| 17 Queryable<E> take(int count); |
| 18 |
| 19 /** |
| 20 * Returns a lazy [Queryable] that stops once [f] is not satisfied any more. |
| 21 * |
| 22 * When iterating over the new [Queryable], the iterator will pass through all |
| 23 * elements of [this] while the predicate [f] is satisfied. When the iterator |
| 24 * encounters an element [:e:] that does not satisfy [f] it discards [:e:] |
| 25 * and will not provide any more elements. |
| 26 */ |
| 27 Queryable<E> takeWhile(bool f(E element)); |
| 28 |
| 29 /** |
| 30 * Returns a lazy [Queryable] where the first [count] elements are ignored. |
| 31 * |
| 32 * If [this] produces less than [count] elements, then the resulting |
| 33 * [Queryable] will not produce any element at all. |
| 34 */ |
| 35 Queryable<E> skip(int count); |
| 36 |
| 37 /** |
| 38 * Returns a lazy [Queryable] that discards the longest leading sequence of |
| 39 * elements that all satisfy [f]. |
| 40 * |
| 41 * When iterating over the new [Queryable], the iterator will skip all |
| 42 * elements of [this] until the given predicate [f] is not satisfied. From |
| 43 * that moment on, all elements are passed through. |
| 44 */ |
| 45 Queryable<E> skipWhile(bool f(E element)); |
| 46 |
| 47 /** |
| 48 * TODO(floitsch): can we have something like this? It would definitely be |
| 49 * handy. |
| 50 */ |
| 51 // Queryable<E> ofType(Type type); |
| 52 |
| 53 /** |
| 54 * Returns a lazy [Queryable] that ignores duplicates. |
| 55 * |
| 56 * When iterating over the return [Queryable] duplicate elements, determined |
| 57 * by the given [compare] function, are ignored. That is, the iterator will |
| 58 * pass through the first occurence of the duplicates but will skip the |
| 59 * following ones. |
| 60 */ |
| 61 Queryable<E> distinct([int compare = Compareable.compareTo]); |
| 62 |
| 63 /** |
| 64 * Returns the first element that satisfies the given predicate [f]. |
| 65 * |
| 66 * If none matches the result of invoking the [defaultValue] function is |
| 67 * returned. By default, without a given [defaultValue], an exception is |
| 68 * thrown. |
| 69 * TODO(floitsch): which one? |
| 70 */ |
| 71 E firstMatching(bool f(E element), { E defaultValue() }); |
| 72 |
| 73 /** |
| 74 * Returns the last element that satisfies the given predicate [f]. |
| 75 * |
| 76 * If none matches the result of invoking the [defaultValue] function is |
| 77 * returned. By default, without a given [defaultValue], an exception is |
| 78 * thrown. |
| 79 * TODO(floitsch): which one? |
| 80 */ |
| 81 E lastMatching(bool f(E element), { E defaultValue() }); |
| 82 |
| 83 /** |
| 84 * Returns the single element that satisfies [f]. If no or more than one |
| 85 * element match an exception is thrown. |
| 86 * TODO(floitsch): which one? |
| 87 */ |
| 88 E single(bool f(E element)); |
| 89 |
| 90 /** |
| 91 * Returns the [index]th element. |
| 92 * |
| 93 * Iterating over a queryable that has less than [index] elements will throw |
| 94 * an exception. |
| 95 * TODO(floitsch): which one? |
| 96 */ |
| 97 E elementAt(int index); |
| 98 } |
| OLD | NEW |