【发布时间】:2010-02-04 21:05:36
【问题描述】:
我可以将什么函数作为 FOO 放在这里以在最后产生 true ?我玩过 hash-set(仅对前 2 个值正确)、conj 和 concat,但我知道我没有正确处理单元素 vs set 条件。
(defn mergeMatches [propertyMapList]
"Take a list of maps and merges them combining values into a set"
(reduce #(merge-with FOO %1 %2) {} propertyMapList))
(def in
(list
{:a 1}
{:a 2}
{:a 3}
{:b 4}
{:b 5}
{:b 6} ))
(def out
{ :a #{ 1 2 3}
:b #{ 4 5 6} })
; this should return true
(= (mergeMatches in) out)
处理这个问题最惯用的方法是什么?
【问题讨论】:
标签: functional-programming clojure