RangeIterable.count constructor
Creates an iterable that describes a sequence starting at start
and containing
count
elements.
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
(inclusive) to start + count
(exclusive). Having the value of count
be zero will
return an empty interval. Having the value of count
be less than zero will result in
an error.
If step is not 1, the values in the interval will skip step times. For
example, a start
of 2, a count
of 3, and an step of 2 will result in the iterable [2, 4, 6].
If step is negative, the iterable will instead count down from start
, e.g. the
previous start
and count
values with an step of -2 will result in the iterable
[2, 0, -2]. Having the value of step be zero will result in an error.
Implementation
RangeIterable.count(
int start,
int count, {
this.step = 1,
}) : assert(step != 0, 'The interval must be a positive integer.'),
assert(count >= 0, 'The count must be a positive integer.'),
start = step > 0 ? start : start - (count * -step) + 1,
end = step > 0 ? start + (count * step) - 1 : start;