开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜