```val componentArgs: List<Pair<Int, Compone...
# announcements
s
Copy code
val componentArgs: List<Pair<Int, Component>> = args
        .mapIndexed { idx, it -> idx to it }
        .filter { it.second is Component }
        .map { it.first to it.second as Component }
Is there a neater way of writing this? I want to store index to args value only if it is Component
k
What's the type of
args
?
Assuming it's something like
List<Any>
this should work:
Copy code
val componentArgs = args
    .filterIsInstance(Component::class)
    .mapIndexed(::Pair)
Where that last line in synthatic sugar for
{idx, it -> idx to it}
.
s
but that would just give me 0,1,2,3. right?
k
Ah right, I didn't think about that.
k
Maybe you can do a safe cast first (
as?
operator) and then filter on whether the result isn't null?