Gavin Ray
07/26/2022, 6:10 PMList
version but you never know, figured I'd ask others:
fun recur(...): Sequence<*> = sequence {
yield(...)
getQueryRelations(innerRequest).forEach {
yieldAll(
recur(...)
)
}
}
fun recur(...): List<*> {
return listOf(...) + getQueryRelations(innerRequest).flatMap {
recur(...)
}
}
ephemient
07/26/2022, 6:28 PMgetQueryRelations(innerRequest)
is a suspend fun
then your sequence
version can't be used directly. sequenceOf(...) + getQueryRelations(innerRequest).asSequence().flatMap { ... }
could be used thoughbuildList {
add(...)
getQueryRelations(innerRequest).flatMapTo(this) { recur(...) }
}
or
getQueryRelations(innerRequest).flatMapTo(mutableListOf(...)) { recur(...) }
instead of your second option, to avoid one whole list copyGavin Ray
07/26/2022, 7:03 PM.flatMapTo(this)
I had never thought of that, that's pretty clever!