IntRange constructor
Returns an iterable of integers from start
inclusive to stop
inclusive
with step
.
Examples: IntRange(0, 5); // (0, 1, 2, 3, 4, 5) IntRange(0, 10, 2); // (0, 2, 4, 6, 8, 10) IntRange(5, -5); // (5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5)
Implementation
factory IntRange(int start, int stop, [int step = 1]) {
if (step == Duration()) {
throw ArgumentError.value(step, 'step', 'cannot be 0');
}
if (stop < start) {
if (!step.isNegative) {
step = -step;
}
} else {
if (step.isNegative) {
step = -step;
}
}
return IntRange._(start, stop, step);
}