Aris Guimerá
Aris Guimerá

Reputation: 1017

Map list of objects with condition

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

Answers (1)

IlyaMuravjov
IlyaMuravjov

Reputation: 2502

You can do it like this:

myObjectList = myObjectList.map {
    if (it !in listObjectIDontWantModify) it.copy(value = newValue)
    else it
}

Upvotes: 1

Related Questions