Dan Rusu
12/10/2024, 9:07 PMStefan Oltmann
12/10/2024, 10:35 PMDan Rusu
12/10/2024, 10:42 PMStefan Oltmann
12/11/2024, 6:03 AMDan Rusu
12/11/2024, 7:55 AMStefan Oltmann
12/11/2024, 8:18 AMArjan van Wieringen
12/11/2024, 11:08 AMmikehearn
12/11/2024, 3:43 PMKlitos Kyriacou
12/11/2024, 4:08 PMImmutableArray<T>
implement List<T>
, and ImmutableIntArray
implement List<Int>
? If it does make sense, it may make these classes more versatile.
2. In your readme, when comparing to Immutable Lists, are you referring to the kotlinx immutable collections library? If so, how did you figure that attempted mutation throws exception? That's the whole point of immutable lists, they're not like the regular List
which is read-only but possibly mutable (see ).Dan Rusu
12/11/2024, 4:56 PMImmutableIntArray
doesn't implement List<Int>
(etc.) because that would result in auto-boxing every single time an element is accessed because we can't override a method and change the return type from a reference type to a primitive type. This would affect the performance significantly and make Immutable Arrays no longer applicable for any sort of number crunching. Note that Immutable Arrays maximize the use of the primitive variants in order to minimize memory and improve performance so you can easily end up with a primitive immutable array even if you work with generic types since performing something like val peopleWeights = people.map { it.weightKg }
produces an ImmutableFloatArray
if the weightKg
property type is Float
. Immutable Arrays have the asList()
method which returns a compatible list wrapper without copying the backing array. Alternatively, you can use toList()
to create a standalone list copy.
2. I updated the readme to clarify that the comparison is against Java immutable lists such as those from the Google Guava library. I should probably add another section to compare against kotlinx immutable lists. I'm just wondering whether I should wait for the kotlinx library to stabilize to avoid creating any sort of misconceptions in case they decide to change the direction or implementation details.Klitos Kyriacou
12/11/2024, 5:19 PMImmutableIntArray
could implement List<Int>
instead of using asList()
but, of course, that would mean that indexing would create unwanted boxing.
I wouldn't hold my breath about kotlinx immutables. They're been in alpha for several years, and as I understand it, the current focus of JetBrains is to work on the K2 compiler and stabilize some other official libraries first, so stabilizing immutables is way into the future. Nevertheless, it is quite usable and has very few issues reported. I doubt the eventually released version will differ much from today.Arjan van Wieringen
12/11/2024, 6:15 PMStefan Oltmann
12/11/2024, 9:55 PMDan Rusu
12/11/2024, 10:19 PMStefan Oltmann
12/11/2024, 11:27 PMArjan van Wieringen
12/12/2024, 5:33 AMStefan Oltmann
12/12/2024, 6:23 AMmikehearn
12/13/2024, 9:03 AMmikehearn
12/13/2024, 9:03 AM