Chromium Code Reviews| Index: sdk/lib/core/iterable.dart |
| diff --git a/sdk/lib/core/iterable.dart b/sdk/lib/core/iterable.dart |
| index 0f846397285b2dfa8e3cd49d8d1b5fc6d48b1159..9128b05afbcc84ee45c1c6fb9120270128d0e85e 100644 |
| --- a/sdk/lib/core/iterable.dart |
| +++ b/sdk/lib/core/iterable.dart |
| @@ -148,6 +148,52 @@ abstract class Iterable<E> { |
| } |
| /** |
| + * Find the least element in the iterable. |
| + * |
| + * Returns null if the iterable is empty. |
| + * Otherwise returns an element [:x:] of this [Iterable] so that |
| + * [:x:] is not greater than [:y:] (that is, [:compare(x, y) <= 0:]) for all |
| + * other elements [:y:] in the iterable. |
| + * |
| + * The [compare] function must be a proper [Comparator<T>]. If a function is |
| + * not provided, [compare] defaults to [Comparable.compare]. |
| + */ |
| + E min([int compare(E a, E b)]) { |
| + if (compare == null) compare = Comparable.compare; |
| + Iterator it = iterator; |
| + if (!it.moveNext()) return null; |
| + E min = it.current; |
| + while (it.moveNext) { |
|
Sean Eagan
2013/01/02 16:35:13
it.moveNext()
|
| + E current = it.current; |
| + if (compare(min, current) > 0) min = current; |
| + } |
| + return min; |
| + } |
| + |
| + /** |
| + * Find the largest element in the iterable. |
| + * |
| + * Returns null if the iterable is empty. |
| + * Otherwise returns an element [:x:] of this [Iterable] so that |
| + * [:x:] is not smaller than [:y:] (that is, [:compare(x, y) >= 0:]) for all |
| + * other elements [:y:] in the iterable. |
| + * |
| + * The [compare] function must be a proper [Comparator<T>]. If a function is |
| + * not provided, [compare] defaults to [Comparable.compare]. |
| + */ |
| + E max([int compare(E a, E b)]) { |
| + if (compare == null) compare = Comparable.compare; |
| + Iterator it = iterator; |
| + if (!it.moveNext()) return null; |
| + E max = it.current; |
| + while (it.moveNext) { |
|
Sean Eagan
2013/01/02 16:35:13
it.moveNext()
|
| + E current = it.current; |
| + if (compare(max, current) < 0) max = current; |
| + } |
| + return max; |
| + } |
| + |
| + /** |
| * Returns true if there is no element in this collection. |
| */ |
| bool get isEmpty => !iterator.moveNext(); |