range static method

Arr<int> range(
  1. int start,
  2. int end, {
  3. int step = 1,
})

An array of int in the range [start..end), where start >= end or start <= end. step must be positive.

Implementation

@pragma("vm:prefer-inline")
static Arr<int> range(int start, int end, {int step = 1}) {
  assert(step > 0, "'step' must be positive.");
  if (start < end) {
    return Arr<int>.generate(((end - start) + step - 1) ~/ step,
        (index) => start + (index * step));
  } else {
    return Arr<int>.generate(((start - end) + step - 1) ~/ step,
        (index) => start - (index * step));
  }
}