OLD | NEW |
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 return value; | 47 return value; |
48 } | 48 } |
49 | 49 |
50 bool every(bool f(E element)) { | 50 bool every(bool f(E element)) { |
51 for (E element in this) { | 51 for (E element in this) { |
52 if (!f(element)) return false; | 52 if (!f(element)) return false; |
53 } | 53 } |
54 return true; | 54 return true; |
55 } | 55 } |
56 | 56 |
57 String join([String separator]) { | 57 String join([String separator = ""]) { |
58 Iterator<E> iterator = this.iterator; | 58 Iterator<E> iterator = this.iterator; |
59 if (!iterator.moveNext()) return ""; | 59 if (!iterator.moveNext()) return ""; |
60 StringBuffer buffer = new StringBuffer(); | 60 StringBuffer buffer = new StringBuffer(); |
61 if (separator == null || separator == "") { | 61 if (separator == null || separator == "") { |
62 do { | 62 do { |
63 buffer.write("${iterator.current}"); | 63 buffer.write("${iterator.current}"); |
64 } while (iterator.moveNext()); | 64 } while (iterator.moveNext()); |
65 } else { | 65 } else { |
66 buffer.write("${iterator.current}"); | 66 buffer.write("${iterator.current}"); |
67 while (iterator.moveNext()) { | 67 while (iterator.moveNext()) { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 return value; | 238 return value; |
239 } | 239 } |
240 | 240 |
241 bool every(bool f(E element)) { | 241 bool every(bool f(E element)) { |
242 for (E element in this) { | 242 for (E element in this) { |
243 if (!f(element)) return false; | 243 if (!f(element)) return false; |
244 } | 244 } |
245 return true; | 245 return true; |
246 } | 246 } |
247 | 247 |
248 String join([String separator]) { | 248 String join([String separator = ""]) { |
249 Iterator<E> iterator = this.iterator; | 249 Iterator<E> iterator = this.iterator; |
250 if (!iterator.moveNext()) return ""; | 250 if (!iterator.moveNext()) return ""; |
251 StringBuffer buffer = new StringBuffer(); | 251 StringBuffer buffer = new StringBuffer(); |
252 if (separator == null || separator == "") { | 252 if (separator == null || separator == "") { |
253 do { | 253 do { |
254 buffer.write("${iterator.current}"); | 254 buffer.write("${iterator.current}"); |
255 } while (iterator.moveNext()); | 255 } while (iterator.moveNext()); |
256 } else { | 256 } else { |
257 buffer.write("${iterator.current}"); | 257 buffer.write("${iterator.current}"); |
258 while (iterator.moveNext()) { | 258 while (iterator.moveNext()) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 E elementAt(int index) { | 373 E elementAt(int index) { |
374 if (index is! int || index < 0) throw new RangeError.value(index); | 374 if (index is! int || index < 0) throw new RangeError.value(index); |
375 int remaining = index; | 375 int remaining = index; |
376 for (E element in this) { | 376 for (E element in this) { |
377 if (remaining == 0) return element; | 377 if (remaining == 0) return element; |
378 remaining--; | 378 remaining--; |
379 } | 379 } |
380 throw new RangeError.value(index); | 380 throw new RangeError.value(index); |
381 } | 381 } |
382 } | 382 } |
OLD | NEW |