Chromium Code Reviews| Index: sdk/lib/core/iterable.dart |
| diff --git a/sdk/lib/core/iterable.dart b/sdk/lib/core/iterable.dart |
| index 6d10da9fa125fbe1b17cc9329c0bcf4544baa6c9..31e11b2e8f95468f5fb899c1825eaa0d95826211 100644 |
| --- a/sdk/lib/core/iterable.dart |
| +++ b/sdk/lib/core/iterable.dart |
| @@ -54,6 +54,30 @@ abstract class Iterable<E> { |
| } |
| /** |
| + * Create an `Iterable<int>` iterating from `from` to `to`, inclusive. |
| + * |
| + * The iteration starts with `from` as the first value, and then |
| + * progresses towards `to` in increments of `step`, and stops when reaching |
| + * or overshooting `to`. If it hits `to` the `to` value is included, |
|
floitsch
2014/09/09 09:37:14
Strongly oppose.
We have a getRange in this class
|
| + * otherwise it isn't. |
| + * |
| + * If `to` is less than `from`, the values are in decreasing order. |
| + * |
| + * The [step] value must always be positive. It defaults to `1`. |
| + */ |
| + static Iterable<int> range(int from, int to, {int step: 1}) { |
| + if (step <= 0) { |
| + throw new RangeError.value("Step must be positive, was $step"); |
| + } |
| + final int delta = to - from; |
| + if (delta < 0) { |
| + step = -step; |
| + } |
| + final int steps = delta ~/ step + 1; |
| + return new Iterable<int>.generate(steps, (n) => from + n * step); |
| + } |
| + |
| + /** |
| * Returns a new `Iterator` that allows iterating the elements of this |
| * `Iterable`. |
| */ |