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

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

问题描述

我有一个 array-map 我正在 asoc 将一些值放入其中.在一定大小之后,返回的值是 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

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

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