https://kotlinlang.org logo
#language-proposals
Title
# language-proposals
m

Michael de Kaste

08/08/2022, 10:16 AM
based on a post of mine in "getting-started" https://kotlinlang.slack.com/archives/C0B8MA7FA/p1659464960124589 currently its possible to define an inner function within builders. If you have recursive logic, this is nice to work with. e.g. for a personal project I can easily do this:
Copy code
fun holeFiller(spaces: Int, totalSum: Int): List<List<Int>> = buildList {
    fun fill(sumToGo: Int, list: List<Int> = emptyList()) {
        when (list.size) {
            spaces - 1 -> add(list + sumToGo)
            else -> for (i in 0..sumToGo) {
                fill(sumToGo - i, list + i)
            }
        }
    }
    fill(totalSum)
}
However, if I want to have this with a sequence, the function "fill" needs to be specified as
Copy code
suspend fun SequenceScope<List<Int>>.fill
It would be nice if an inner function of a sequence implicitly works like this
y

Youssef Shoaib [MOD]

08/08/2022, 1:27 PM
How will this work when specifying function references? There are use cases where someone wants to define an inner function that is explicitly not
suspend
or explicitly isn't within a
Sequence
m

Michael de Kaste

08/08/2022, 1:31 PM
those inner functions HAVE to be called within the scope of the sequence right? That means they need to be suspended? Or can you give me an example where that isn't the case?
2 Views