-
-
Save rohitsat13/6eac5886bf05931add6f4debb5a01fd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2021 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 */ | |
data class MyData( | |
- val nums: List<Int> | |
+ val nums: PersistentList<Int> | |
) | |
- val myInts = mutableListOf(1, 2, 3, 4) | |
- val myObj = MyData(myInts) | |
- myInts.add(5) // Fails to compile with PersistentList, but mutates with List | |
+ val newData = myObj.copy( | |
+ nums = myObj.nums.mutate { it += 5 } // Mutate returns a new PersistentList | |
+ ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment