karelpeeters
07/29/2017, 3:15 PMval 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
Thread in Slack Conversation
Assuming it's something like List<Any>
this should work:
val componentArgs = args
.filterIsInstance(Component::class)
.mapIndexed(::Pair)
Where that last line in synthatic sugar for {idx, it -> idx to it}
.