Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: sdk/lib/core/queryable.dart

Issue 11366111: Make Iterable more powerful (and lazy). (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Undo unintended change. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 abstract class Queryable<E> extends Iterable<E> {
Lasse Reichstein Nielsen 2012/11/12 09:38:03 Needs a description on the class. What is it?
floitsch 2012/11/16 22:31:07 Done.
6 /**
7 * Returns a lazy [Queryable] with at most [count] elements.
8 *
9 * If [this] produces less than [count] elements, then the resulting
10 * [Queryable] will produce less than [count] elements, too.
11 */
12 Queryable<E> take(int count);
13
14 /**
15 * Returns a lazy [Queryable] that stops once [f] is not satisfied any more.
16 *
17 * When iterating over the new [Queryable], the iterator will pass through all
18 * elements of [this] until the given predicate [f] is not satisfied. From
19 * that moment on no other elements are passed through.
Lasse Reichstein Nielsen 2012/11/12 09:38:03 Is the first non-matching element included? (I ass
floitsch 2012/11/16 22:31:07 Yes, but the comments need to be improved by a lot
20 */
21 Queryable<E> takeWhile(bool f(E element));
22
23 /**
24 * Returns a lazy [Queryable] where the first [count] elements are ignored.
25 *
26 * If [this] produces less than [count] elements, then the resulting
27 * [Queryable] will not produce any element at all.
28 */
29 Queryable<E> skip(int count);
30
31 /**
32 * Returns a lazy [Queryable] that discards the longest leading sequence of
33 * elements that all satisfy [f].
34 *
35 * When iterating over the new [Queryable], the iterator will skip all
36 * elements of [this] until the given predicate [f] is not satisfied. From
37 * that moment on, all elements are passed through.
38 */
39 Queryable<E> skipWhile(bool f(E element));
40
41 /**
42 * TODO(floitsch): can we have something like this? It would definitely be
43 * handy.
Lasse Reichstein Nielsen 2012/11/12 09:38:03 We don't have an easy way to test if an object is
44 */
45 // Queryable<E> ofType(Type type);
46
47 /**
48 * Returns a lazy [Queryable] that ignores duplicates.
49 *
50 * When iterating over the return [Queryable] duplicate elements, determined
51 * by the given [compare] function, are ignored. That is, the iterator will
52 * pass through the first occurence of the duplicates but will skip the
53 * following ones.
54 */
55 Queryable<E> distinct([int compare = Compareable.compareTo]);
56
57 /**
58 * Returns a lazy [Queryable] that skips all elements except the first
59 * matching one.
60 *
61 * This method is equivalent to [:this.where(f).take(1):].
62 *
63 * TODO(floitsch): C# throws an exception if none matches. Not sure if that
64 * helps.
65 */
66 Queryable<E> firstMatching(bool f(E element));
Lasse Reichstein Nielsen 2012/11/12 09:38:03 Why is this a Queryable if it only returns one ele
floitsch 2012/11/16 22:31:07 doh. yes. fixed and all the others below.
67
68 /**
69 * Returns a lazy [Queryable] that skips all elements except the first
70 * matching one. If no element matches, then the [defaultValue] is returned.
71 */
72 Queryable<E> firstMatchingOrDefault(bool f(E element), E defaultValue);
Lasse Reichstein Nielsen 2012/11/12 09:38:03 Make the defaultValue a closure returning the valu
floitsch 2012/11/16 22:31:07 Done.
73
74 /**
75 * Returns a lazy [Queryable] that skips all elements except the last
76 * matching one.
77 *
78 * TODO(floitsch): C# throws an exception if none matches. Not sure if that
79 * helps.
80 */
81 Queryable<E> lastMatching(bool f(E element));
Lasse Reichstein Nielsen 2012/11/12 09:38:03 Why not eager and returning a value? This queryabl
floitsch 2012/11/16 22:31:07 Done.
82
83 /**
84 * Returns a lazy [Queryable] that skips all elements except the last
85 * matching one. If no element matches, then the [defaultValue] is returned.
86 */
87 Queryable<E> lastMatchingOrDefault(bool f(E element), E defaultValue);
Lasse Reichstein Nielsen 2012/11/12 09:38:03 As above, make defaultValue an optional function t
floitsch 2012/11/16 22:31:07 Done.
88
89 /**
90 * Returns a lazy [Queryable] that skips all elements except the one
91 * satisfying [f]. If no or more than one element match, then an exception
Lasse Reichstein Nielsen 2012/11/12 09:38:03 "If no element match, or if more than one element
floitsch 2012/11/16 22:31:07 added TODO.
92 * is thrown.
93 */
94 Queryable<E> single(bool f(E element));
95
96 /**
97 * Returns a lazy [Queryable] that returns the [index]th element.
98 *
99 * Iterating over a queryable that has less than [index] elements will throw
100 * an error. This method is thus not equivalent to
Lasse Reichstein Nielsen 2012/11/12 09:38:03 Have you considered which error? Seems like a Rang
floitsch 2012/11/16 22:31:07 No. Added TODO.
101 * [:this.skip(index - 1).take(1):].
102 */
103 Queryable<E> elementAt(int index);
104 }
OLDNEW
« sdk/lib/core/list.dart ('K') | « sdk/lib/core/map.dart ('k') | sdk/lib/core/sequences.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698