Function: -union

-union is a byte-compiled function defined in dash.el.

Signature

(-union LIST1 LIST2)

Documentation

Return a new list of distinct elements appearing in either LIST1 or LIST2.

The test for equality is done with equal, or with -compare-fn if that is non-nil.

Source Code

;; Defined in ~/.emacs.d/elpa/dash-20260221.1346/dash.el
(defun -union (list1 list2)
  "Return a new list of distinct elements appearing in either LIST1 or LIST2.

The test for equality is done with `equal', or with `-compare-fn'
if that is non-nil."
  (declare (important-return-value t))
  (let ((lists (list list1 list2)) test len union)
    (cond ((null (or list1 list2)))
          ;; Use a hash table if `-compare-fn' is a known hash table
          ;; test function and the lists are long enough.
          ((and (setq test (dash--hash-test-fn))
                (> (setq len (dash--size+ (length list1) (length list2)))
                   dash--short-list-length))
           (let ((ht (make-hash-table :test test :size len)))
             (dolist (l lists)
               (--each l (unless (gethash it ht)
                           (puthash it t ht)
                           (push it union))))))
          ((let ((member (dash--member-fn)))
             (dolist (l lists)
               (--each l (unless (funcall member it union) (push it union)))))))
    (nreverse union)))