vaskir
06/08/2017, 5:26 PMdata class Item(
val n: Int,
val Children: List<Item> = emptyList()
)
fun Item.allSubitems(): List<Item> =
this.Children.flatMap {
mutableListOf(it).apply { this.addAll(it.allSubitems()) }
}
fun main(args: Array<String>) {
val item = Item(0, listOf(Item(1, listOf(Item(2), Item(3)))))
println(item.allSubitems().map { it.n })
}
[1, 2, 3]