A sequence of integers starting from
start
to
end
counting up or down.
It excludes the
end
value when counting up and the
start
value when counting down.
Examples:
new ExclusiveRange(1, 5, true) | (1,2,3,4) |
new ExclusiveRange(0, 0, true) | () |
new ExclusiveRange(0, -1, true) | () |
new ExclusiveRange(-1, 0, true) | (-1) |
new ExclusiveRange(5, 1, false) | (4,3,2,1) |
new ExclusiveRange(0, 0, false) | () |
new ExclusiveRange(-1, 0, false) | () |
new ExclusiveRange(0, -1, false) | (-1) |
As opposed to
IntegerRange
this class meets the requirements to iterate arrays or lists without
the need for further guards, e.g.
for(i: new ExclusiveRange(0, list.size, true))
list.get(i)...
for(i: new ExclusiveRange(array.length, 0, false))
array.get(i)...
for(i: new ExclusiveRange(0, string.indexOf('x'), true)
string.charAt(i)...