kotlinx.collections.immutable
kotlinx.collections.immutable copied to clipboard
Road to Beta
The primary focus of our current development is to promote the library from Alpha to Beta stability level. The implementation is already robust, with few bugs reported since its inception. However, some fundamental design choices need to be made before we finalize the library API design. Thus, we will focus on the following areas:
- [ ]
Immutablevs.Persistentinterfaces:- Decide whether to have both
ImmutableandPersistentsets of interfaces.- https://github.com/Kotlin/kotlinx.collections.immutable/issues/1
- Provide implementations of
Immutablecollections that are not persistent.- https://github.com/Kotlin/kotlinx.collections.immutable/issues/62
- Decide whether to have both
- [ ] Naming:
- Determine if member functions of persistent collections that return a new instance should use a different naming scheme.
- https://github.com/Kotlin/kotlinx.collections.immutable/issues/8
- https://github.com/Kotlin/kotlinx.collections.immutable/issues/139
- Consider shorter names for persistent collections.
- https://github.com/Kotlin/kotlinx.collections.immutable/issues/14
- Review the library’s public API, specifically extension function names.
- https://github.com/Kotlin/kotlinx.collections.immutable/issues/65
- Determine if member functions of persistent collections that return a new instance should use a different naming scheme.
- [ ] Providing static assurance of the underlying implementation:
- Expose implementation classes.
- https://github.com/Kotlin/kotlinx.collections.immutable/issues/66
- Expose ordered types.
- https://github.com/Kotlin/kotlinx.collections.immutable/issues/106
- https://github.com/Kotlin/kotlinx.collections.immutable/issues/128
- Prohibit custom implementations of
ImmutableandPersistentinterfaces.- https://github.com/Kotlin/kotlinx.collections.immutable/issues/147
- Expose implementation classes.
- [ ] Feature parity with stdlib collections:
- Resolve the issue of stdlib collection extensions for persistent collections.
- https://github.com/Kotlin/kotlinx.collections.immutable/issues/10
- https://github.com/Kotlin/kotlinx.collections.immutable/issues/12
- https://github.com/Kotlin/kotlinx.collections.immutable/issues/123
- https://github.com/Kotlin/kotlinx.collections.immutable/issues/181
- Resolve the issue of stdlib collection extensions for persistent collections.
The grouping of these that is used above seems a bit strange. It seems to me that issues #62, #66, #147, and #10 are basically the same issue, but they are grouped in different categories. In each of these, people are requesting true implementations of statically checkable immutable collections (ones which can't be subclassed to be non-immutable).
Provide implementations of Immutable collections that are not persistent. immutableOf(…) functions shouldn't be deprecated, and should return Immutable instead of Persistent* #62
#62 is not about Immutable* collections that aren't implemented as Persistent* collections. It's about keeping immutable*Of(…) functions, and their return type being Immutable*. If I need a collection that should never be modified, I do not want to expose functions that could be thought to mutate the collection. I know that the functions won't modify the underlying object, but I don't want to clutter the API of my immutable collection instance with those methods.
When the return type is Immutable*, that gives you the option to later create immutable objects that aren't actually persistent, in case you can optimize some performance or other characteristics.
The addition of a few simple static functions will take almost no maintenance effort, and barely adds to the complexity of the API. It provides more flexibility for future performance optimizations, and provides users a simple way to improve/tailor their usage of the library.
One avenue to consider is that eventually multi field value classes will come to the language, and with them copying functions. If Persistent collections can expose copying functions, that'd allow for using them in a way that's near-identical to normal collections. However, that likely wouldn't work with the current design of having the methods named exactly the same as mutating methods.
In other words, I imagine a world where one can write:
var map: PersistentMap<K, V> = ...
map.put(k, v)
And get the correct result.
Just food for thought!
The counterargument to this is that one should use mutate anyways. In fact, a copying version of mutate is likely the the optimal design here!