這可以被分解成簡單的步驟,然後擰入一個簡單的 「一個班輪」
(->> (slurp "data") ; read the data from the file.
(re-seq #"[^{} \n]+") ; split it into strings ignoring \n and { }.
(partition 2) ; group it into key, value pairs
(map vec) ; turn the pairs into vectors because into wants this.
(into {})) ; mash them in turn into a single map.
{":something1" "1", ":something2" "2", ":something3" "3", ":something4" "4"}
或者,如果你喜歡的嵌套形式,你可以寫相同的代碼是這樣的:
user> (into {} (map vec (partition 2 (re-seq #"[^{} \n]+" (slurp "data")))))
{":something1" "1", ":something2" "2", ":something3" "3", ":something4" "4"}
將您輸入包含重複鍵,重複的值,或兩者兼而有之? –
我已編輯帖子。 – mzdravkov