I am trying to figure out why we have IntRange and...
# announcements
f
I am trying to figure out why we have IntRange and IntProgression
d
IntProgression
can have a step, you could for example iterate from 0 to 10 in steps of 2 (0, 2, 4, 6, 8, 10).
IntRange
is an
IntProgression
where the step is always 1 and as such represents a closed range.
f
so the word "Range" implies that no numbers are skipped?
ie no step
d
Yes
The range [0, 10] includes all numbers 0 through 10.
That's why you can do
5 in 0..10
but not
5 in (0..10 step 2)
Actually you can do that. Huh.
Ah, but the range simply does a check where as the progression needs to loop through all the numbers to see if one matches
f
makes sense
in a way, ranges are similar to arrays, right?
d
No, a range is really just a start and end element
f
ok
and what about progression
could you say that it is similar to an array
I mean I get that it generates the actual values in the iterators next function
but it can do a lot of the same things that an array with the same numbers could do
d
That is true, yes. It's an Iterable.
k
Huh that's stupid, the progressions should implement
contains
and
indexOf
etc!
f
What are you referring to exactly
k
Ah, but the range simply does a check where as the progression needs to loop through all the numbers to see if one matches