quick one: Please, who knows an idiomatic way to s...
# getting-started
s
quick one: Please, who knows an idiomatic way to select a previous or next element in a collection in Kotlin?
Copy code
val list = listOf(...)
val current = ...
val next = list[list.indexOf(current) + 1]
val previous = list[list.indexOf(current) - 1]
k
I don't think you can do a lot better than that.
🙏 1
s
sounds like you want a doubly linked list
p
But this would help only if iterate to your
current
element through this iterator, and not just getting
current
element from outside.