Как toUppercase () одно свойство списка в kotlin с картой? - PullRequest
0 голосов
/ 30 июня 2019

Не понимаю, почему заглавные буквы не применяются при возврате данных?

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
}

1 Ответ

1 голос
/ 30 июня 2019
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, так как он ответил первым, а не просто добавил его в качестве ответа.

...