Open rnett opened 3 years ago
Stdlib mapOf
and mutableMapOf
create an ordered map.
Similarly, persistentMapOf
returns an empty ordered map. All modification operations preserve the ordered behavior of the map. When you assign a map accepted as a function argument, the result of toPersistentMap()
can be used. toPersistentMap()
is no-op if the reciever is already an ordered map, and creates an ordered map with elements of the receiver otherwise.
Let's keep this issue open for further discussion.
Any update on this? Open to contributions?
It seems like what's missing are interfaces for PersistentOrderedMap
and PersistentOrderedSet
, rather than exposing the implementation classes.
I'm having the exact same issue. I'm not sure if the suggested solution is the best alternative, but I would find it valuable to have a way of enforcing if the preservation of order is needed or not.
Especially, since PersistentSet
is described as:
A generic persistent unordered collection of elements that does not support duplicate elements, and supports adding and removing elements.
+1 about exposing PersistentOrderedMap and PersistentOrderedSet 🙏
I have a few situations where I want to enforce that my map is ordered, say for a list of settings profiles that are keyed by name, but also should have a defined order. This isn't currently possible (here or in the stdlib, although stdlib at least has
LinkedHashMap
) since althoughpersistentMapOf
usesPersistentOrderedMap
, the type ofPersistentOrderedMap
isn't exposed.This might be more appropriate as a stdlib issue, let me know if so.