OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // patch classes for Int8List ..... Float64List and ByteData implementations. | 5 // patch classes for Int8List ..... Float64List and ByteData implementations. |
6 | 6 |
7 patch class Int8List { | 7 patch class Int8List { |
8 /* patch */ factory Int8List(int length) { | 8 /* patch */ factory Int8List(int length) { |
9 return new _Int8Array(length); | 9 return new _Int8Array(length); |
10 } | 10 } |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 } | 300 } |
301 | 301 |
302 Iterable map(f(int element)) { | 302 Iterable map(f(int element)) { |
303 return IterableMixinWorkaround.mapList(this, f); | 303 return IterableMixinWorkaround.mapList(this, f); |
304 } | 304 } |
305 | 305 |
306 String join([String separator = ""]) { | 306 String join([String separator = ""]) { |
307 return IterableMixinWorkaround.join(this, separator); | 307 return IterableMixinWorkaround.join(this, separator); |
308 } | 308 } |
309 | 309 |
310 dynamic reduce(dynamic initialValue, | 310 dynamic reduce(dynamic combine(value, element)) { |
floitsch
2013/04/10 15:14:07
Return type is int.
Lasse Reichstein Nielsen
2013/04/11 07:54:04
Why are the iterables untyped? I was assuming type
floitsch
2013/04/11 09:36:41
If they work only on ints and nums then they shoul
| |
311 dynamic combine(dynamic initialValue, element)) { | 311 return IterableMixinWorkaround.reduce(this, combine); |
312 return IterableMixinWorkaround.reduce(this, initialValue, combine); | |
313 } | 312 } |
314 | 313 |
315 dynamic fold(dynamic initialValue, | 314 dynamic fold(dynamic initialValue, |
316 dynamic combine(dynamic initialValue, element)) { | 315 dynamic combine(dynamic initialValue, element)) { |
317 return IterableMixinWorkaround.fold(this, initialValue, combine); | 316 return IterableMixinWorkaround.fold(this, initialValue, combine); |
318 } | 317 } |
319 | 318 |
320 Iterable where(bool f(int element)) { | 319 Iterable where(bool f(int element)) { |
321 return IterableMixinWorkaround.where(this, f); | 320 return IterableMixinWorkaround.where(this, f); |
322 } | 321 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 if (length > 0) return this[length - 1]; | 442 if (length > 0) return this[length - 1]; |
444 throw new StateError("No elements"); | 443 throw new StateError("No elements"); |
445 } | 444 } |
446 | 445 |
447 int get single { | 446 int get single { |
448 if (length == 1) return this[0]; | 447 if (length == 1) return this[0]; |
449 if (length == 0) throw new StateError("No elements"); | 448 if (length == 0) throw new StateError("No elements"); |
450 throw new StateError("More than one element"); | 449 throw new StateError("More than one element"); |
451 } | 450 } |
452 | 451 |
453 int min([int compare(int a, int b)]) => | |
454 IterableMixinWorkaround.min(this, compare); | |
455 | |
456 int max([int compare(int a, int b)]) => | |
457 IterableMixinWorkaround.max(this, compare); | |
458 | |
459 void removeRange(int start, int length) { | 452 void removeRange(int start, int length) { |
460 throw new UnsupportedError( | 453 throw new UnsupportedError( |
461 "Cannot remove from a non-extendable array"); | 454 "Cannot remove from a non-extendable array"); |
462 } | 455 } |
463 | 456 |
464 void insertRange(int start, int length, [initialValue]) { | 457 void insertRange(int start, int length, [initialValue]) { |
465 throw new UnsupportedError( | 458 throw new UnsupportedError( |
466 "Cannot add to a non-extendable array"); | 459 "Cannot add to a non-extendable array"); |
467 } | 460 } |
468 | 461 |
(...skipping 2617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3086 return value; | 3079 return value; |
3087 } | 3080 } |
3088 return object; | 3081 return object; |
3089 } | 3082 } |
3090 | 3083 |
3091 | 3084 |
3092 void _throwRangeError(int index, int length) { | 3085 void _throwRangeError(int index, int length) { |
3093 String message = "$index must be in the range [0..$length)"; | 3086 String message = "$index must be in the range [0..$length)"; |
3094 throw new RangeError(message); | 3087 throw new RangeError(message); |
3095 } | 3088 } |
OLD | NEW |