问题
I have an array-map
which I am assoc
ing some values into it. After a certain size the returned value is a PersistentHashMap
rather than the original PersistentArrayMap
. I've read about this behavior on a few web sites. Is there any way to force the insertion order even after assoc
?
I do have a separate function which will take a ash-map
and a vector of keys, and return a "fresh" array-map
with keys in this order, but it means that for each assoc, I have to extract the keys first, cons/conj the new key to the vector, then create a new array-map. Seems kludgey, even if written in a separate function.
Is there a more direct language-supported way of keeping insertion order even on large-ish (>10, but < 50) keys array-map?
In case it's relevant, I'm using a list of array-maps as data into an incanter dataset and then outputting to excel. The save-xls function keeps the order of the keys/columns.
Thanks
回答1:
You can use an ordered map: https://github.com/flatland/ordered
来源:https://stackoverflow.com/questions/12034142/how-to-get-a-clojure-array-map-to-maintain-insertion-order-after-assoc