所以我有這樣的數據結構:如何在Clojure中的更扁平數據結構中獲得相同的值?
(def params
{:site1
{:index-element
{:date "2012-10-10"
:title "Hello"}
:subpage-element
{:time "9:00"
:location "Toronto"}}
:site2 …})
我想將其更改爲更扁平化的數據結構
(def new-params
{1
{:name :site1
:date ["2012-10-10" :index-element]
:title ["Hello" :index-element]
:time ["9:00" :subpage-element]
:location ["Toronto" :subpage-element]}
2 …})
爲了得到我想要我做的結果:
(mapv #(-> params % :index-element vals)
(keys params))
我如何獲得與新參數相同的結果?
偉大的職位,謝謝!我真的很驚訝,這是複雜的。我想你是對的,即使flatten貼圖趨向於更乾淨,在這種情況下,返回與index-element關聯的val會更加複雜。 – leontalbot
@ user1184248:使用'for'使其更加清晰 – Ankur