| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The [Iterable] interface allows to get an [Iterator] out of an | 8 * The [Iterable] interface allows to get an [Iterator] out of an |
| 9 * [Iterable] object. | 9 * [Iterable] object. |
| 10 * | 10 * |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 return result; | 316 return result; |
| 317 } | 317 } |
| 318 | 318 |
| 319 /** | 319 /** |
| 320 * Returns the first element that satisfies the given predicate [f]. | 320 * Returns the first element that satisfies the given predicate [f]. |
| 321 * | 321 * |
| 322 * If none matches, the result of invoking the [orElse] function is | 322 * If none matches, the result of invoking the [orElse] function is |
| 323 * returned. By default, when [orElse] is `null`, a [StateError] is | 323 * returned. By default, when [orElse] is `null`, a [StateError] is |
| 324 * thrown. | 324 * thrown. |
| 325 */ | 325 */ |
| 326 E firstMatching(bool test(E value), { E orElse() }) { | 326 E firstWhere(bool test(E value), { E orElse() }) { |
| 327 // TODO(floitsch): check that arguments are of correct type? | 327 // TODO(floitsch): check that arguments are of correct type? |
| 328 for (E element in this) { | 328 for (E element in this) { |
| 329 if (test(element)) return element; | 329 if (test(element)) return element; |
| 330 } | 330 } |
| 331 if (orElse != null) return orElse(); | 331 if (orElse != null) return orElse(); |
| 332 throw new StateError("No matching element"); | 332 throw new StateError("No matching element"); |
| 333 } | 333 } |
| 334 | 334 |
| 335 /** | 335 /** |
| 336 * Returns the last element that satisfies the given predicate [f]. | 336 * Returns the last element that satisfies the given predicate [f]. |
| 337 * | 337 * |
| 338 * If none matches, the result of invoking the [orElse] function is | 338 * If none matches, the result of invoking the [orElse] function is |
| 339 * returned. By default, when [orElse] is [:null:], a [StateError] is | 339 * returned. By default, when [orElse] is [:null:], a [StateError] is |
| 340 * thrown. | 340 * thrown. |
| 341 */ | 341 */ |
| 342 E lastMatching(bool test(E value), {E orElse()}) { | 342 E lastWhere(bool test(E value), {E orElse()}) { |
| 343 // TODO(floitsch): check that arguments are of correct type? | 343 // TODO(floitsch): check that arguments are of correct type? |
| 344 E result = null; | 344 E result = null; |
| 345 bool foundMatching = false; | 345 bool foundMatching = false; |
| 346 for (E element in this) { | 346 for (E element in this) { |
| 347 if (test(element)) { | 347 if (test(element)) { |
| 348 result = element; | 348 result = element; |
| 349 foundMatching = true; | 349 foundMatching = true; |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 if (foundMatching) return result; | 352 if (foundMatching) return result; |
| 353 if (orElse != null) return orElse(); | 353 if (orElse != null) return orElse(); |
| 354 throw new StateError("No matching element"); | 354 throw new StateError("No matching element"); |
| 355 } | 355 } |
| 356 | 356 |
| 357 /** | 357 /** |
| 358 * Returns the single element that satisfies [f]. If no or more than one | 358 * Returns the single element that satisfies [f]. If no or more than one |
| 359 * element match then a [StateError] is thrown. | 359 * element match then a [StateError] is thrown. |
| 360 */ | 360 */ |
| 361 E singleMatching(bool test(E value)) { | 361 E singleWhere(bool test(E value)) { |
| 362 // TODO(floitsch): check that argument is of correct type? | 362 // TODO(floitsch): check that argument is of correct type? |
| 363 E result = null; | 363 E result = null; |
| 364 bool foundMatching = false; | 364 bool foundMatching = false; |
| 365 for (E element in this) { | 365 for (E element in this) { |
| 366 if (test(element)) { | 366 if (test(element)) { |
| 367 if (foundMatching) { | 367 if (foundMatching) { |
| 368 throw new StateError("More than one matching element"); | 368 throw new StateError("More than one matching element"); |
| 369 } | 369 } |
| 370 result = element; | 370 result = element; |
| 371 foundMatching = true; | 371 foundMatching = true; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 */ | 433 */ |
| 434 abstract class BidirectionalIterator<T> extends Iterator<T> { | 434 abstract class BidirectionalIterator<T> extends Iterator<T> { |
| 435 /** | 435 /** |
| 436 * Move back to the previous element. | 436 * Move back to the previous element. |
| 437 * | 437 * |
| 438 * Returns true and updates [current] if successful. Returns false | 438 * Returns true and updates [current] if successful. Returns false |
| 439 * and sets [current] to null if there is no previous element. | 439 * and sets [current] to null if there is no previous element. |
| 440 */ | 440 */ |
| 441 bool movePrevious(); | 441 bool movePrevious(); |
| 442 } | 442 } |
| OLD | NEW |