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

Side by Side Diff: sdk/lib/collection/iterable.dart

Issue 15263004: Adding isNotEmpty property to collection and string. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix template generation Created 7 years, 6 months 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
« no previous file with comments | « sdk/lib/collection/hash_set.dart ('k') | sdk/lib/collection/linked_hash_map.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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.collection; 5 part of dart.collection;
6 6
7 /** 7 /**
8 * This [Iterable] mixin implements all [Iterable] members except `iterator`. 8 * This [Iterable] mixin implements all [Iterable] members except `iterator`.
9 * 9 *
10 * All other methods are implemented in terms of `iterator`. 10 * All other methods are implemented in terms of `iterator`.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 int count = 0; 88 int count = 0;
89 Iterator it = iterator; 89 Iterator it = iterator;
90 while (it.moveNext()) { 90 while (it.moveNext()) {
91 count++; 91 count++;
92 } 92 }
93 return count; 93 return count;
94 } 94 }
95 95
96 bool get isEmpty => !iterator.moveNext(); 96 bool get isEmpty => !iterator.moveNext();
97 97
98 bool get isNotEmpty => !isEmpty;
99
98 Iterable<E> take(int n) { 100 Iterable<E> take(int n) {
99 return new TakeIterable<E>(this, n); 101 return new TakeIterable<E>(this, n);
100 } 102 }
101 103
102 Iterable<E> takeWhile(bool test(E value)) { 104 Iterable<E> takeWhile(bool test(E value)) {
103 return new TakeWhileIterable<E>(this, test); 105 return new TakeWhileIterable<E>(this, test);
104 } 106 }
105 107
106 Iterable<E> skip(int n) { 108 Iterable<E> skip(int n) {
107 return new SkipIterable<E>(this, n); 109 return new SkipIterable<E>(this, n);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 int count = 0; 282 int count = 0;
281 Iterator it = iterator; 283 Iterator it = iterator;
282 while (it.moveNext()) { 284 while (it.moveNext()) {
283 count++; 285 count++;
284 } 286 }
285 return count; 287 return count;
286 } 288 }
287 289
288 bool get isEmpty => !iterator.moveNext(); 290 bool get isEmpty => !iterator.moveNext();
289 291
292 bool get isNotEmpty => !isEmpty;
293
290 Iterable<E> take(int n) { 294 Iterable<E> take(int n) {
291 return new TakeIterable<E>(this, n); 295 return new TakeIterable<E>(this, n);
292 } 296 }
293 297
294 Iterable<E> takeWhile(bool test(E value)) { 298 Iterable<E> takeWhile(bool test(E value)) {
295 return new TakeWhileIterable<E>(this, test); 299 return new TakeWhileIterable<E>(this, test);
296 } 300 }
297 301
298 Iterable<E> skip(int n) { 302 Iterable<E> skip(int n) {
299 return new SkipIterable<E>(this, n); 303 return new SkipIterable<E>(this, n);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 E elementAt(int index) { 379 E elementAt(int index) {
376 if (index is! int || index < 0) throw new RangeError.value(index); 380 if (index is! int || index < 0) throw new RangeError.value(index);
377 int remaining = index; 381 int remaining = index;
378 for (E element in this) { 382 for (E element in this) {
379 if (remaining == 0) return element; 383 if (remaining == 0) return element;
380 remaining--; 384 remaining--;
381 } 385 }
382 throw new RangeError.value(index); 386 throw new RangeError.value(index);
383 } 387 }
384 } 388 }
OLDNEW
« no previous file with comments | « sdk/lib/collection/hash_set.dart ('k') | sdk/lib/collection/linked_hash_map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698