Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin 复制列表,但修改字段_Kotlin_Transformation - Fatal编程技术网

Kotlin 复制列表,但修改字段

Kotlin 复制列表,但修改字段,kotlin,transformation,Kotlin,Transformation,我有一张人的名单 我想将每个人的状态从“活动”更改为“非活动”。我无法修改原始数据结构或原始数据 fun changeClone(list: List<People>) { val newList = MutableList<People>() list.forEach { person -> //i feel there has to be an easier faster way to do this in kotlin

我有一张
人的名单

我想将每个人的状态从
“活动”
更改为
“非活动”
。我无法修改原始数据结构或原始数据

fun changeClone(list: List<People>) {

    val newList = MutableList<People>()

    list.forEach { person ->
        //i feel there has to be an easier faster way to do this in kotlin
        val newPerson(person.name, ...., status = "not-active")
        newList.add(newPerson)
    }
    showUi(newList)
}
我可以将
val状态
转换为
var
,但实际上我不应该修改原始数据。那么,我能做些什么使这更容易呢


另外,所有其他数据必须相同。

我没有检查,但是
list.map{it.copy(status=“not active”)}
应该可以工作。见文件:(“复制”部分)。
val newList = list.map { person ->
    person.copy(status = "not-active")
}
val newList = list.map { person ->
    person.copy(status = "not-active")
}