https://kotlinlang.org logo
#announcements
Title
# announcements
r

Ruckus

08/16/2017, 8:51 PM
@lab Something like this?
Copy code
val filtered = (0..list.lastIndex).asSequence()
    .filter { it in indexes }
    .map(list::get)
    .toList()
(I haven't tested it)
k

karelpeeters

08/16/2017, 8:52 PM
If you don't care about order
val result = set.map { list[it] }.toList()
also works.
👍 1
r

Ruckus

08/16/2017, 8:58 PM
Very true, and it looks a lot nicer. I've always felt using mapping functions on int ranges looks dirty.
k

karelpeeters

08/16/2017, 9:00 PM
And if you do care about order there's also this:
set.toList().sort().map { list[it] }
. Everything to avoid int ranges!
😆 1
2 Views