rangeTo method

Iterable<int> rangeTo (
  1. int n
)

Creates an Iterable<int> that contains all values from current integer until (including) the value n.

Example:

0.rangeTo(5); // [0, 1, 2, 3, 4, 5]
3.rangeTo(1); // [3, 2, 1]

Implementation

Iterable<int> rangeTo(int n) {
  ArgumentError.checkNotNull(n, "n");
  int count = (n - this).abs() + 1;
  int direction = (n - this).sign;
  int i = this - direction;
  return Iterable.generate(count, (int index) {
    return i += direction;
  });
}