如何在assoc之后获取clojure数组映射以保持插入顺序? [英] How to get a clojure array-map to maintain insertion order after assoc?

查看:27
本文介绍了如何在assoc之后获取clojure数组映射以保持插入顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 array-map,我正在将一些值assoc放入其中.达到一定大小后,返回值是PersistentHashMap 而不是原始的PersistentArrayMap.我在一些网站上读到过这种行为.有没有办法在 assoc 之后强制插入顺序?

I have an array-map which I am associng 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?

我确实有一个单独的函数,它将接受一个 ash-map 和一个键向量,并按照这个顺序返回一个带有键的新鲜"array-map,但这意味着对于每个关联,我必须首先提取键,cons/conj 向量的新键,然后创建一个新的数组映射.看起来很笨拙,即使是用单独的函数编写的.

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.

是否有更直接的语言支持的方式来保持插入顺序,即使在大型(> 10,但 <50)键数组映射上?

Is there a more direct language-supported way of keeping insertion order even on large-ish (>10, but < 50) keys array-map?

如果相关,我将使用数组映射列表作为数据进入 incanter 数据集,然后输出到 excel.save-xls 函数保持键/列的顺序.

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.

谢谢

推荐答案

您可以使用有序映射:https://github.com/flatland/ordered

这篇关于如何在assoc之后获取clojure数组映射以保持插入顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆