Function: map--merge

map--merge is a byte-compiled function defined in map.el.gz.

Signature

(map--merge MERGE TYPE &rest MAPS)

Documentation

Merge into a map of TYPE all the key/value pairs in MAPS.

MERGE is a function that takes the target MAP, a KEY and its VALUE, merges KEY and VALUE into MAP, and returns the result. MAP may be of a type other than TYPE.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/map.el.gz
(defun map--merge (merge type &rest maps)
  "Merge into a map of TYPE all the key/value pairs in MAPS.
MERGE is a function that takes the target MAP, a KEY and its
VALUE, merges KEY and VALUE into MAP, and returns the result.
MAP may be of a type other than TYPE."
  ;; Use a hash table internally if `type' is a list.  This avoids
  ;; both quadratic lookup behavior and the type ambiguity of nil.
  (let* ((tolist (memq type '(list alist plist)))
         (result (map-into (pop maps)
                            ;; Use same testfn as `map-elt' gv setter.
                           (cond ((eq type 'plist) '(hash-table :test eq))
                                 (tolist '(hash-table :test equal))
                                 (type)))))
    (dolist (map maps)
      (map-do (lambda (key value)
                (setq result (funcall merge result key value)))
              map))
    ;; Convert internal representation to desired type.
    (if tolist (map-into result type) result)))