Use flatMapTo(mutableListOf(), f) instead of flatMap(f).toMutableList()

Proprietary

flatMap { f } allocates a List<R> and toMutableList copies it. flatMapTo(mutableListOf(), f) writes directly into the target without the intermediate.

org.openrewrite.kotlin.performance.UseFlatMapToForFlatMapToMutableList$KtRecipe
mod run . --recipe='org.openrewrite.kotlin.performance.UseFlatMapToForFlatMapToMutableList$KtRecipe'

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.