Stop Using mutableListOf + toList(): Meet Kotlin’s buildList, buildMap, and buildSet
A Familiar But Slightly Awkward Pattern If you’ve written Kotlin for a while, you’ve almost certainly written code like this: fun getActiveUsers(users: List): List { val result = mutableListOf() for (user in users) { if (user.isActive) result.add(user) if (user.isPremium) result.add(user.copy(label = “Premium”)) } return result.toList() // convert back to read-only } The pattern works, but […]

