Please point me elsewhere if this isn't the best c...
# getting-started
e
Please point me elsewhere if this isn't the best channel, but I'm wondering why
IntRange
and
IntProgression
don't support the
get()
operator like
List
does. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/get.html
j
I'm guessing because lists are usually backed by arrays that can support a get in constant time. Ranges and progressions rarely need a get and a get would provide no performance benefits over the client iterating over the range
1
h
Alternatively you write it yourself. For some implementations you could easily write a constant version.
e
Thank you, @Jacob. As you probably know, there is an
elementAt()
method. Looking at the documentation, I see that
elementAt()
is terminal, which answers my underlying unstated question of the difference between
get()
and
elementAt()
.
@hfhbd You're right, but this was meant as a why-did-they-do-that question, not a how-do-I-do-that. Sorry for not being more clear.
j
I was not aware. I assume you meant this one https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/element-at.html which doesn't have docs about being terminal as terminal is a concept specific to sequences.