如何使用地图在 kotlin 中使用大写()列表中的一个 属性?

How toUppercase() one property of a list in kotlin with map?

我不明白为什么 return 数据不应用大写?

val userList: LiveData<List<UserData>> = Transformations.map(userRepository.getUsers()) { data ->
    data.forEach {
        it.name.toUpperCase()
        Log.i("uppercase", it.name.toUpperCase()) //uppercase working here
    }
    Log.i("data", data.toString())  //uppercase not there
    return@map data
}
val userList: LiveData<List<UserData>> = Transformations.map(userRepository.getUsers()) { data ->
    data.forEach {
        it.name = it.name.toUpperCase() //This is what you're missing, as explained by @forpas in the comment section.
        Log.i("uppercase", it.name.toUpperCase()) //uppercase working here
    }
    Log.i("data", data.toString())  //uppercase now there
    return@map data
}

功劳归功于@forpas,因为他首先回答,但不只是将其添加为答案。