ziad
01/19/2018, 5:16 PMdata class MyDataClass(
val myMap: Map<Int, String> = mapOf()
)
fun addElementToMyDataClass(myInstance : MyDataClass, key : Int, value : String): MyDataClass {
val mutableCopyOfMap = myInstance.myMap.toMutableMap()
mutableCopyOfMap[key] = value
return myInstance.copy(myMap = mutableCopyOfMap)
}
jk
01/19/2018, 6:24 PM+
on an immutable map returns a new immutable map anyway, it would be simpler just to write:
fun addElementToMyDataClass(myInstance : MyDataClass, key : Int, value : String): MyDataClass {
return myInstance.copy(myMap = myInstance.myMap + (key to value))
}
ziad
01/19/2018, 6:24 PMjk
01/19/2018, 6:24 PMnkiesel
01/19/2018, 7:15 PMfullTariffList.add(tariffInfo.copy())
. Your problem is that the fullTariffList contains pointers to the objects. So you really have (A,B,A,B,A.B) in your list and thus setting the type to "vendor" in the last loop iteration modifies all entriesziad
01/19/2018, 7:18 PM