aggregate_function_question.kt
# announcements
l
aggregate_function_question.kt
s
I think there’s a couple ways you could go about doing this
w
A little "gross", but this works? (didn't tested)
Copy code
println(list.sortedBy { min(it.index, it.children?.minBy { it.index }?.index ?: Int.MAX_VALUE) })
s
that’d only work for one layer of nesting I think
you’re going to need some kind of traversal function to find the lowest index within the page tree
l
Actually 1 layer of nesting should be sufficient. Thanks! Will try it out
a
Copy code
fun Page.mindex(): Int = (listOf(index) + (children?.map { it.mindex() } ?: listOf<Int>())).min() ?: Int.MAX_VALUE
l
@wbertan that worked
@alex.hart thanks!
a
Mine works for any amount of nesting 😉
👍 1
and Int.MAX_VALUE could realistically be replaced with wrapping whole thing w. requireNotNull because you’ll always have a minimum of 1 item