Similar to merge-with, but the contents of each key are merged in
parallel using f.
f - a function of 2 arguments.
data - a collection of hashes.
(defn preduce
"Similar to merge-with, but the contents of each key are merged in
parallel using f.
f - a function of 2 arguments.
data - a collection of hashes."
[f data]
(let [data-1 (map (fn [h] (map-values #(list %) h)) data)
merged (doall (apply merge-with concat data-1))
; Groups w/ multiple elements are identified for parallel processing
[complex simple] (separate (fn [[key vals]] (> (count vals) 1)) merged)
fold-group (fn [[key vals]] {key (reduce f vals)})
fix-single (fn [[key [val]]] [key val])]
(apply merge (concat (pmap fold-group merged) (map fix-single simple)))))
Comments top
No comments for preduce. Log in to add a comment.