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

Side by Side Diff: tool/input_sdk/lib/collection/iterable.dart

Issue 1122313002: Typing fixes to eliminate casts/dcalls (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Rebase Created 5 years, 7 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
« no previous file with comments | « tool/input_sdk/lib/collection/hash_map.dart ('k') | tool/input_sdk/lib/collection/set.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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 Iterable<E> skip(int n) { 114 Iterable<E> skip(int n) {
115 return new SkipIterable<E>(this, n); 115 return new SkipIterable<E>(this, n);
116 } 116 }
117 117
118 Iterable<E> skipWhile(bool test(E value)) { 118 Iterable<E> skipWhile(bool test(E value)) {
119 return new SkipWhileIterable<E>(this, test); 119 return new SkipWhileIterable<E>(this, test);
120 } 120 }
121 121
122 E get first { 122 E get first {
123 Iterator it = iterator; 123 Iterator<E> it = iterator;
124 if (!it.moveNext()) { 124 if (!it.moveNext()) {
125 throw IterableElementError.noElement(); 125 throw IterableElementError.noElement();
126 } 126 }
127 return it.current; 127 return it.current;
128 } 128 }
129 129
130 E get last { 130 E get last {
131 Iterator it = iterator; 131 Iterator<E> it = iterator;
132 if (!it.moveNext()) { 132 if (!it.moveNext()) {
133 throw IterableElementError.noElement(); 133 throw IterableElementError.noElement();
134 } 134 }
135 E result; 135 E result;
136 do { 136 do {
137 result = it.current; 137 result = it.current;
138 } while(it.moveNext()); 138 } while(it.moveNext());
139 return result; 139 return result;
140 } 140 }
141 141
142 E get single { 142 E get single {
143 Iterator it = iterator; 143 Iterator<E> it = iterator;
144 if (!it.moveNext()) throw IterableElementError.noElement(); 144 if (!it.moveNext()) throw IterableElementError.noElement();
145 E result = it.current; 145 E result = it.current;
146 if (it.moveNext()) throw IterableElementError.tooMany(); 146 if (it.moveNext()) throw IterableElementError.tooMany();
147 return result; 147 return result;
148 } 148 }
149 149
150 E firstWhere(bool test(E value), { E orElse() }) { 150 E firstWhere(bool test(E value), { E orElse() }) {
151 for (E element in this) { 151 for (E element in this) {
152 if (test(element)) return element; 152 if (test(element)) return element;
153 } 153 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 281 }
282 282
283 List<E> toList({ bool growable: true }) => 283 List<E> toList({ bool growable: true }) =>
284 new List<E>.from(this, growable: growable); 284 new List<E>.from(this, growable: growable);
285 285
286 Set<E> toSet() => new Set<E>.from(this); 286 Set<E> toSet() => new Set<E>.from(this);
287 287
288 int get length { 288 int get length {
289 assert(this is! EfficientLength); 289 assert(this is! EfficientLength);
290 int count = 0; 290 int count = 0;
291 Iterator it = iterator; 291 Iterator<E> it = iterator;
292 while (it.moveNext()) { 292 while (it.moveNext()) {
293 count++; 293 count++;
294 } 294 }
295 return count; 295 return count;
296 } 296 }
297 297
298 bool get isEmpty => !iterator.moveNext(); 298 bool get isEmpty => !iterator.moveNext();
299 299
300 bool get isNotEmpty => !isEmpty; 300 bool get isNotEmpty => !isEmpty;
301 301
302 Iterable<E> take(int n) { 302 Iterable<E> take(int n) {
303 return new TakeIterable<E>(this, n); 303 return new TakeIterable<E>(this, n);
304 } 304 }
305 305
306 Iterable<E> takeWhile(bool test(E value)) { 306 Iterable<E> takeWhile(bool test(E value)) {
307 return new TakeWhileIterable<E>(this, test); 307 return new TakeWhileIterable<E>(this, test);
308 } 308 }
309 309
310 Iterable<E> skip(int n) { 310 Iterable<E> skip(int n) {
311 return new SkipIterable<E>(this, n); 311 return new SkipIterable<E>(this, n);
312 } 312 }
313 313
314 Iterable<E> skipWhile(bool test(E value)) { 314 Iterable<E> skipWhile(bool test(E value)) {
315 return new SkipWhileIterable<E>(this, test); 315 return new SkipWhileIterable<E>(this, test);
316 } 316 }
317 317
318 E get first { 318 E get first {
319 Iterator it = iterator; 319 Iterator<E> it = iterator;
320 if (!it.moveNext()) { 320 if (!it.moveNext()) {
321 throw IterableElementError.noElement(); 321 throw IterableElementError.noElement();
322 } 322 }
323 return it.current; 323 return it.current;
324 } 324 }
325 325
326 E get last { 326 E get last {
327 Iterator it = iterator; 327 Iterator<E> it = iterator;
328 if (!it.moveNext()) { 328 if (!it.moveNext()) {
329 throw IterableElementError.noElement(); 329 throw IterableElementError.noElement();
330 } 330 }
331 E result; 331 E result;
332 do { 332 do {
333 result = it.current; 333 result = it.current;
334 } while(it.moveNext()); 334 } while(it.moveNext());
335 return result; 335 return result;
336 } 336 }
337 337
338 E get single { 338 E get single {
339 Iterator it = iterator; 339 Iterator<E> it = iterator;
340 if (!it.moveNext()) throw IterableElementError.noElement(); 340 if (!it.moveNext()) throw IterableElementError.noElement();
341 E result = it.current; 341 E result = it.current;
342 if (it.moveNext()) throw IterableElementError.tooMany(); 342 if (it.moveNext()) throw IterableElementError.tooMany();
343 return result; 343 return result;
344 } 344 }
345 345
346 E firstWhere(bool test(E value), { E orElse() }) { 346 E firstWhere(bool test(E value), { E orElse() }) {
347 for (E element in this) { 347 for (E element in this) {
348 if (test(element)) return element; 348 if (test(element)) return element;
349 } 349 }
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 length += ELLIPSIS_SIZE + OVERHEAD; 591 length += ELLIPSIS_SIZE + OVERHEAD;
592 } 592 }
593 } 593 }
594 if (elision != null) { 594 if (elision != null) {
595 parts.add(elision); 595 parts.add(elision);
596 } 596 }
597 parts.add(penultimateString); 597 parts.add(penultimateString);
598 parts.add(ultimateString); 598 parts.add(ultimateString);
599 } 599 }
600 } 600 }
OLDNEW
« no previous file with comments | « tool/input_sdk/lib/collection/hash_map.dart ('k') | tool/input_sdk/lib/collection/set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698