gpt4 book ai didi

clojure - 如何对 clojure map 集进行排序?

转载 作者:行者123 更新时间:2023-12-03 01:12:50 25 4
gpt4 key购买 nike

我有一组类似这样的 map :

#{
{:name "a" :value "b" ... more stuff here}
{:name "b" :value "b" ... more stuff here}
{:name "b" :value "b" ... more stuff here}
{:name "a" :value "b" ... more stuff here}
{:name "c" :value "b" ... more stuff here}
{:name "a" :value "b" ... more stuff here}
}

:我想要获得一个有序列表,就像 sql 按名称排序一样:

[
{:name "a" :value "b" ... more stuff here}
{:name "a" :value "b" ... more stuff here}
{:name "a" :value "b" ... more stuff here}
{:name "b" :value "b" ... more stuff here}
{:name "b" :value "b" ... more stuff here}
{:name "c" :value "b" ... more stuff here}
]

:我该怎么做?

最佳答案

函数sort-by就是您要找的:

(def s
#{
{:name "d" :value "b" }
{:name "b" :value "b" }
{:name "c" :value "b" }
})
(sort-by :name s)

关于clojure - 如何对 clojure map 集进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5395491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com