开发者

How to find out all keys in a set of maps?

开发者 https://www.devze.com 2023-02-22 02:15 出处:网络
If I have a set of maps like this (def a #{ {:a 1 :b 2} {:a 3 :b 4} {:b 1 :c 2} {:d 1 :e 2} {:d 1 :y 2} }) : how can I find out all the keys? so doing :

If I have a set of maps like this

(def a #{
          {:a 1 :b 2}
          {:a 3 :b 4}
          {:b 1 :c 2}
          {:d 1 :e 2}
          {:d 1 :y 2}
})

: how can I find out all the keys? so doing :

(find-all-keys a)

:retu开发者_运维问答rns:

(:a :b :c :d :e :y)

?


Another way:

(distinct (mapcat keys a))


Almost the same way:

(set (mapcat keys a))


Something like:

user=> (into #{} (flatten (map keys a)))
#{:y :a :c :b :d :e}


Another way:

(reduce #(into %1 (keys %2))  #{}  a)
0

精彩评论

暂无评论...
验证码 换一张
取 消