Chromium Code Reviews| 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 | 295 |
| 296 String join([String separator = ""]) { | 296 String join([String separator = ""]) { |
| 297 return IterableMixinWorkaround.join(this, separator); | 297 return IterableMixinWorkaround.join(this, separator); |
| 298 } | 298 } |
| 299 | 299 |
| 300 dynamic reduce(dynamic combine(value, element)) { | 300 dynamic reduce(dynamic combine(value, element)) { |
| 301 return IterableMixinWorkaround.reduce(this, combine); | 301 return IterableMixinWorkaround.reduce(this, combine); |
| 302 } | 302 } |
| 303 | 303 |
| 304 dynamic fold(dynamic initialValue, | 304 dynamic fold(dynamic initialValue, |
| 305 dynamic combine(dynamic initialValue, element)) { | 305 dynamic combine(dynamic initialValue, element)) { |
|
Lasse Reichstein Nielsen
2013/05/29 07:44:18
Inconsistent use of dynamic: it should be on eleme
floitsch
2013/05/29 14:51:12
Changed to `num`. That works for ints and doubles.
| |
| 306 return IterableMixinWorkaround.fold(this, initialValue, combine); | 306 return IterableMixinWorkaround.fold(this, initialValue, combine); |
| 307 } | 307 } |
| 308 | 308 |
| 309 Iterable where(bool f(int element)) { | 309 Iterable where(bool f(element)) { |
| 310 return IterableMixinWorkaround.where(this, f); | 310 return IterableMixinWorkaround.where(this, f); |
| 311 } | 311 } |
| 312 | 312 |
| 313 Iterable expand(Iterable f(int element)) { | 313 Iterable expand(Iterable f(element)) { |
| 314 return IterableMixinWorkaround.expand(this, f); | 314 return IterableMixinWorkaround.expand(this, f); |
| 315 } | 315 } |
| 316 | 316 |
| 317 Iterable take(int n) { | 317 Iterable take(int n) { |
| 318 return IterableMixinWorkaround.takeList(this, n); | 318 return IterableMixinWorkaround.takeList(this, n); |
| 319 } | 319 } |
| 320 | 320 |
| 321 Iterable takeWhile(bool test(int value)) { | 321 Iterable takeWhile(bool test(value)) { |
|
Lasse Reichstein Nielsen
2013/05/29 07:44:18
value => element.
More below.
floitsch
2013/05/29 14:51:12
Done.
| |
| 322 return IterableMixinWorkaround.takeWhile(this, test); | 322 return IterableMixinWorkaround.takeWhile(this, test); |
| 323 } | 323 } |
| 324 | 324 |
| 325 Iterable skip(int n) { | 325 Iterable skip(int n) { |
| 326 return IterableMixinWorkaround.skipList(this, n); | 326 return IterableMixinWorkaround.skipList(this, n); |
| 327 } | 327 } |
| 328 | 328 |
| 329 Iterable skipWhile(bool test(int value)) { | 329 Iterable skipWhile(bool test(value)) { |
| 330 return IterableMixinWorkaround.skipWhile(this, test); | 330 return IterableMixinWorkaround.skipWhile(this, test); |
| 331 } | 331 } |
| 332 | 332 |
| 333 bool every(bool f(element)) { | 333 bool every(bool f(element)) { |
| 334 return IterableMixinWorkaround.every(this, f); | 334 return IterableMixinWorkaround.every(this, f); |
| 335 } | 335 } |
| 336 | 336 |
| 337 bool any(bool f(element)) { | 337 bool any(bool f(element)) { |
| 338 return IterableMixinWorkaround.any(this, f); | 338 return IterableMixinWorkaround.any(this, f); |
| 339 } | 339 } |
| 340 | 340 |
| 341 int firstWhere(bool test(int value), {int orElse()}) { | 341 firstWhere(bool test(value), {orElse()}) { |
| 342 return IterableMixinWorkaround.firstWhere(this, test, orElse); | 342 return IterableMixinWorkaround.firstWhere(this, test, orElse); |
| 343 } | 343 } |
| 344 | 344 |
| 345 int lastWhere(bool test(int value), {int orElse()}) { | 345 lastWhere(bool test(value), {orElse()}) { |
| 346 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | 346 return IterableMixinWorkaround.lastWhereList(this, test, orElse); |
| 347 } | 347 } |
| 348 | 348 |
| 349 int singleWhere(bool test(int value)) { | 349 singleWhere(bool test(value)) { |
| 350 return IterableMixinWorkaround.singleWhere(this, test); | 350 return IterableMixinWorkaround.singleWhere(this, test); |
| 351 } | 351 } |
| 352 | 352 |
| 353 int elementAt(int index) { | 353 elementAt(int index) { |
| 354 return this[index]; | 354 return this[index]; |
| 355 } | 355 } |
| 356 | 356 |
| 357 bool get isEmpty { | 357 bool get isEmpty { |
| 358 return this.length == 0; | 358 return this.length == 0; |
| 359 } | 359 } |
| 360 | 360 |
| 361 | 361 |
| 362 // Method(s) implementing the List interface. | 362 // Method(s) implementing the List interface. |
| 363 | 363 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 void removeAll(Iterable elements) { | 421 void removeAll(Iterable elements) { |
| 422 throw new UnsupportedError( | 422 throw new UnsupportedError( |
| 423 "Cannot remove from a non-extendable array"); | 423 "Cannot remove from a non-extendable array"); |
| 424 } | 424 } |
| 425 | 425 |
| 426 void retainAll(Iterable elements) { | 426 void retainAll(Iterable elements) { |
| 427 throw new UnsupportedError( | 427 throw new UnsupportedError( |
| 428 "Cannot remove from a non-extendable array"); | 428 "Cannot remove from a non-extendable array"); |
| 429 } | 429 } |
| 430 | 430 |
| 431 void removeWhere(bool test(int element)) { | 431 void removeWhere(bool test(element)) { |
| 432 throw new UnsupportedError( | 432 throw new UnsupportedError( |
| 433 "Cannot remove from a non-extendable array"); | 433 "Cannot remove from a non-extendable array"); |
| 434 } | 434 } |
| 435 | 435 |
| 436 void retainWhere(bool test(int element)) { | 436 void retainWhere(bool test(element)) { |
| 437 throw new UnsupportedError( | 437 throw new UnsupportedError( |
| 438 "Cannot remove from a non-extendable array"); | 438 "Cannot remove from a non-extendable array"); |
| 439 } | 439 } |
| 440 | 440 |
| 441 int get first { | 441 get first { |
| 442 if (length > 0) return this[0]; | 442 if (length > 0) return this[0]; |
| 443 throw new StateError("No elements"); | 443 throw new StateError("No elements"); |
| 444 } | 444 } |
| 445 | 445 |
| 446 int get last { | 446 get last { |
| 447 if (length > 0) return this[length - 1]; | 447 if (length > 0) return this[length - 1]; |
| 448 throw new StateError("No elements"); | 448 throw new StateError("No elements"); |
| 449 } | 449 } |
| 450 | 450 |
| 451 int get single { | 451 get single { |
| 452 if (length == 1) return this[0]; | 452 if (length == 1) return this[0]; |
| 453 if (length == 0) throw new StateError("No elements"); | 453 if (length == 0) throw new StateError("No elements"); |
| 454 throw new StateError("More than one element"); | 454 throw new StateError("More than one element"); |
| 455 } | 455 } |
| 456 | 456 |
| 457 void removeRange(int start, int end) { | 457 void removeRange(int start, int end) { |
| 458 throw new UnsupportedError( | 458 throw new UnsupportedError( |
| 459 "Cannot remove from a non-extendable array"); | 459 "Cannot remove from a non-extendable array"); |
| 460 } | 460 } |
| 461 | 461 |
| (...skipping 2643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3105 return value; | 3105 return value; |
| 3106 } | 3106 } |
| 3107 return object; | 3107 return object; |
| 3108 } | 3108 } |
| 3109 | 3109 |
| 3110 | 3110 |
| 3111 void _throwRangeError(int index, int length) { | 3111 void _throwRangeError(int index, int length) { |
| 3112 String message = "$index must be in the range [0..$length)"; | 3112 String message = "$index must be in the range [0..$length)"; |
| 3113 throw new RangeError(message); | 3113 throw new RangeError(message); |
| 3114 } | 3114 } |
| OLD | NEW |