How to call joinToString with suspending function

This is a toy example of what i want to accomplish:

import kotlinx.coroutines.delay

suspend fun x() {
    val names = listOf("Abe", "David", "Boris") { toUpper() }.joinToString()

suspend fun toUpper(name: String): String {
    return name.toUpperCase()
} { toUpper() }.joinToString() is not nice and android studio says that it can be simplified to

names.joinToString { toUpper() }

Unfortunately this does not work because now there is an error:

Suspension function can just be called in coroutines body

I guess that is because joinToString is not inlined.

Is there a way to overcome this?

I think this is probably a bug in the Kotlin plug-in. It shouldn’t recommend the simplification.

1 Like

You are right. After searching in the issue tracker of the android studio kotlin plugin i found this issue: