to method

Iterable<int> to(
  1. int end, {
  2. int step = 1,
})

Inclusive range as a lazy iterable.

1.to(5); // (1, 2, 3, 4, 5)

Implementation

Iterable<int> to(int end, {int step = 1}) sync* {
  assert(step > 0, 'step must be positive');
  if (this <= end) {
    for (var i = this; i <= end; i += step) {
      yield i;
    }
  } else {
    for (var i = this; i >= end; i -= step) {
      yield i;
    }
  }
}