Vampire
04/24/2026, 11:17 AMjoinToString action while in a suspend function?
Like this (https://pl.kotl.in/7ydf0wXCo):
suspend fun main() {
println(listOf("").joinToString { foo() })
}
suspend fun foo() = "foo"
Of course that version does not work and is majorly oversimplified example.
But how would one get this working properly?Joffrey
04/24/2026, 11:19 AMjoinToString were inline, but it is apparently not. So I guess you would have to write your own inline version of itRobert Jaros
04/24/2026, 11:24 AM.map {} before calling joinToString. I think the result will be the same.Vampire
04/24/2026, 11:26 AMsuspend fun main() {
println(listOf("").map(Any::foo).joinToString())
}
suspend fun Any.foo() = "foo"
When I instead do
suspend fun main() {
println(listOf("").map { it.foo() }.joinToString())
}
suspend fun Any.foo() = "foo"
it works.
Why is the latter working, but the former not?Tanish Azad
04/24/2026, 11:29 AM(T) -> R, but Any::foo is of type KSuspendFunction so its a type mismatch.
.map { it.foo() } make a higher order function of type (T) -> RVampire
04/24/2026, 11:29 AMYoussef Shoaib [MOD]
04/24/2026, 1:09 PMsuspend is a long standing issue. I think I saw something on YouTrack suggesting that they'll improve this, but I can't rememberVampire
04/24/2026, 1:14 PMmap is fine for me.Vampire
04/24/2026, 1:30 PMsequence { ... }?
So like
suspend fun main() {
println(sequence { yield(foo()) }.joinToString())
}
suspend fun foo() = "foo"
which complains with
Restricted suspending functions can invoke member or extension suspending functions only on their restricted coroutine scope.
Youssef Shoaib [MOD]
04/24/2026, 1:30 PMflow instead of sequence.Vampire
04/24/2026, 1:37 PMflow works, thanksYoussef Shoaib [MOD]
04/24/2026, 1:39 PMflow is a `suspend`ing sequence. It's technically slightly slower (I think), since sequence benefits by only `suspend`ing on yield