supaham
07/29/2017, 1:51 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 Componentkarelpeeters
07/29/2017, 3:07 PMargs
?karelpeeters
07/29/2017, 3:15 PMList<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}
.supaham
07/29/2017, 4:03 PMkarelpeeters
07/29/2017, 4:04 PMkarelpeeters
07/29/2017, 4:06 PMas?
operator) and then filter on whether the result isn't null?