RangeIterable constructor
Creates an iterable that contains all elements between start
(inclusive)
and end
(exclusive, optionally inclusive).
This iterable will generate values dynamically in a lazy fashion. When consumed,
the iterable will result in a range of values, typically in the range from start
to end
, including start
but not including end
. Having the value of start
be
greater than end
will result in an error.
If inclusive
is true, end
will be included in the iterable as the last value.
If step
is not 1, the values in the interval will skip step
times. For
example, a range of [2-7] with an step
of 2 will result in the iterable [2, 4, 6].
If step
is negative, the iterable will be reversed, starting from end
and
descending to start
. (If inclusive
is false, the first value will be end - 1
.)
Having the value step
be 0 will result in an error.
Implementation
RangeIterable(
this.start,
int end, {
this.step = 1,
bool inclusive = false,
}) : assert(start != null),
assert(end != null),
assert(end >= start),
assert(step != null),
assert(step != 0, 'The interval must be a non-zero integer.'),
end = inclusive ? end : end - 1;