在clojure中转换嵌套的矢量地图

时间:2016-03-10 21:51:02

标签: clojure

我需要收集:c/name值到嵌套向量中,并以相同的方式转换到第一级。

输入示例:

[:a/name "name" :a/vals [{:b/val [{:c/name "one"}{:c/name "two"}]}
                         {:b/val [{:c/name "three"}]}]]

输出:

[:a/name :a/vals "one, two, three"]

1 个答案:

答案 0 :(得分:0)

这会产生输入的输出,这是你想要的吗?

(defn f [[k1 _ k2 rels]]
  [k1 k2
   (clojure.string/join ", "
     (map :c/name (apply concat (mapcat vals rels))))])