Bill
05/22/2021, 9:45 AMstate.list = state.list.map { listItem in
if listItem.id == action.payload.id {
var listItem = listItem
listItem.title = action.payload.newTitle
return listItem
} else {
return listItem
}
}
kenkyee
05/22/2021, 10:24 AMBill
05/22/2021, 11:04 AMkenkyee
05/22/2021, 11:07 AMBill
05/22/2021, 11:08 AMmkrussel
05/24/2021, 12:19 PMmap
function see the lambda as returning Unit
.
As for the type of state.list
. Ideally that would be of type List
. If it needs to be mutable, then it should be MutableList
and you will need to call toMutableList
on the result of map
.Bill
05/27/2021, 10:17 AMmkrussel
05/27/2021, 12:05 PMstate.list = state.list.map { listItem in
if listItem.id == action.payload.id {
var listItem = listItem
listItem.title = action.payload.newTitle
listItem
} else {
listItem
}
}
Although this is not really doing any mapping.
This is probably better to be in a basic for loop.