Reputation: 1017
I have a list of objects, I would like make something like this
myobjectList = myObjectList.map{ if( !listObjectIDontWantModify.contains(it) it.copy(value = newvalue)}
But return List. I just want modify some objects but keeping all objects.
Upvotes: 0
Views: 300
Reputation: 2502
You can do it like this:
myObjectList = myObjectList.map {
if (it !in listObjectIDontWantModify) it.copy(value = newValue)
else it
}
Upvotes: 1