Join 习惯地图加入clojure?

Join 习惯地图加入clojure?,join,clojure,merge,Join,Clojure,Merge,我有一个如下所示的数据结构: (def conf { :devices [{:alias "OSC Sender", :name "OSC Sender", :ins [{:name "xpos", :type :int, :mutable true}]}, {:alias "const2", :name "const", :outs [{:name "out", :typ

我有一个如下所示的数据结构:

(def conf 
  { :devices [{:alias "OSC Sender",
               :name "OSC Sender",
               :ins [{:name "xpos", :type :int, :mutable true}]},
              {:alias "const2", :name "const",
               :outs [{:name "out", :type :int}]}],
    :connections {"const2.out" "OSC Sender.xpos"},
    :layout [{:alias "const2",
              :x 72.12447405329594,
              :y 99.88499298737729},
             {:alias "tick",
              :x 82.5732819074334,
              :y 133.91374474053296},
             {:alias "OSC Sender",
              :x 185.17741935483872,
              :y 113.90322580645162}]})
我想通过键(特别是
:alias
)加入
:devices
:layout
中的地图,以丰富设备的布局信息

现在,我拼凑出了以下解决方案:

(map (partial reduce merge) (vals (group-by :alias (concat (:devices conf) (:layout conf)))))
这是一个惯用的连接还是其他更好的连接


干杯

您可以使用
clojure.set
命名空间中的
join
函数:

(clojure.set/join (conf :devices) (conf :layout) {:alias :alias})

请注意,返回值是一个集合。省略最后一个参数会导致自然连接;有关详细信息,请参见
(doc clojure.set/join)

marczyk,有关于左、右、n全外连接的想法吗?如果我想保持字典在左边,如果另一边没有匹配项?
clojure.set
不提供任何外部连接函数,但当然可以自己编写。不过,这是另一个问题的主题;事实上,一个以前被问过的问题,例如。