0.8.4-SNAPSHOT Arrow_down_16x16

difference-with

clojure.core.logic

  • (difference-with f & maps)
Returns a map that consists of the first map with the rest of the maps
removed from it. When a key is found in the first map and a later map,
the value from the later map will be combined with the value in the first
map by calling (f val-in-first val-in-later). If this function returns nil
then the key will be removed completely.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core/logic.clj:1869 top

(defn difference-with
  "Returns a map that consists of the first map with the rest of the maps
   removed from it. When a key is found in the first map and a later map,
   the value from the later map will be combined with the value in the first
   map by calling (f val-in-first val-in-later). If this function returns nil
   then the key will be removed completely."
  [f & maps]
  (when (some identity maps)
    (let [empty-is-nil (fn [s] (if (empty? s) nil s))
          merge-entry (fn [m [k v]]
                         (if (contains? m k)
                           (if-let [nv (empty-is-nil (f (get m k) v))]
                             (assoc m k nv)
                             (dissoc m k))
                           m))
          merge-map (fn [m1 m2] (reduce merge-entry (or m1 {}) (seq m2)))]
      (reduce merge-map maps))))
Vars in clojure.core.logic/difference-with:
Used in 0 other vars

Comments top

No comments for difference-with. Log in to add a comment.