| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 int get length { | 141 int get length { |
| 142 int count = 0; | 142 int count = 0; |
| 143 Iterator it = iterator; | 143 Iterator it = iterator; |
| 144 while (it.moveNext()) { | 144 while (it.moveNext()) { |
| 145 count++; | 145 count++; |
| 146 } | 146 } |
| 147 return count; | 147 return count; |
| 148 } | 148 } |
| 149 | 149 |
| 150 /** | 150 /** |
| 151 * Find the least element in the iterable. |
| 152 * |
| 153 * Returns null if the iterable is empty. |
| 154 * Otherwise returns an element [:x:] of this [Iterable] so that |
| 155 * [:x:] is not greater than [:y:] (that is, [:compare(x, y) <= 0:]) for all |
| 156 * other elements [:y:] in the iterable. |
| 157 * |
| 158 * The [compare] function must be a proper [Comparator<T>]. If a function is |
| 159 * not provided, [compare] defaults to [Comparable.compare]. |
| 160 */ |
| 161 T min([int compare(T a, T b)]) { |
| 162 if (compare == null) compare = Comparable.compare; |
| 163 Iterator it = iterator; |
| 164 if (!it.moveNext()) return null; |
| 165 T min = it.current; |
| 166 while (it.moveNext) { |
| 167 T current = it.current; |
| 168 if (compare(min, current) > 0) min = current; |
| 169 } |
| 170 return min; |
| 171 } |
| 172 |
| 173 /** |
| 174 * Find the largest element in the iterable. |
| 175 * |
| 176 * Returns null if the iterable is empty. |
| 177 * Otherwise returns an element [:x:] of this [Iterable] so that |
| 178 * [:x:] is not smaller than [:y:] (that is, [:compare(x, y) >= 0:]) for all |
| 179 * other elements [:y:] in the iterable. |
| 180 * |
| 181 * The [compare] function must be a proper [Comparator<T>]. If a function is |
| 182 * not provided, [compare] defaults to [Comparable.compare]. |
| 183 */ |
| 184 T max([int compare(T a, T b)]) { |
| 185 if (compare == null) compare = Comparable.compare; |
| 186 Iterator it = iterator; |
| 187 if (!it.moveNext()) return null; |
| 188 T max = it.current; |
| 189 while (it.moveNext) { |
| 190 T current = it.current; |
| 191 if (compare(max, current) < 0) max = current; |
| 192 } |
| 193 return max; |
| 194 } |
| 195 |
| 196 /** |
| 151 * Returns true if there is no element in this collection. | 197 * Returns true if there is no element in this collection. |
| 152 */ | 198 */ |
| 153 bool get isEmpty => !iterator.moveNext(); | 199 bool get isEmpty => !iterator.moveNext(); |
| 154 | 200 |
| 155 /** | 201 /** |
| 156 * Returns an [Iterable] with at most [n] elements. | 202 * Returns an [Iterable] with at most [n] elements. |
| 157 * | 203 * |
| 158 * The returned [Iterable] may contain fewer than [n] elements, if [this] | 204 * The returned [Iterable] may contain fewer than [n] elements, if [this] |
| 159 * contains fewer than [n] elements. | 205 * contains fewer than [n] elements. |
| 160 */ | 206 */ |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 _hasSkipped = true; | 565 _hasSkipped = true; |
| 520 while (_iterator.moveNext()) { | 566 while (_iterator.moveNext()) { |
| 521 if (!_f(_iterator.current)) return true; | 567 if (!_f(_iterator.current)) return true; |
| 522 } | 568 } |
| 523 } | 569 } |
| 524 return _iterator.moveNext(); | 570 return _iterator.moveNext(); |
| 525 } | 571 } |
| 526 | 572 |
| 527 E get current => _iterator.current; | 573 E get current => _iterator.current; |
| 528 } | 574 } |
| OLD | NEW |