How can I get the nested keys of a map in clojure?

后端 未结 11 1141
梦如初夏
梦如初夏 2020-12-15 10:59

if my structure is

{ :a :A
  :b :B
  :c {
       :d :D
     }
  :e {
       :f {
            :g :G
            :h :H
          }
     }
}

I

11条回答
  •  粉色の甜心
    2020-12-15 11:18

    (defn keys-in [m]
      (if (or (not (map? m))
              (empty? m))
        '(())
        (for [[k v] m
              subkey (keys-in v)]
          (cons k subkey))))
    

提交回复
热议问题