Function: -intersection
-intersection is a byte-compiled function defined in dash.el.
Signature
(-intersection LIST1 LIST2)
Documentation
Return a new list of distinct elements appearing in both LIST1 and 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 -intersection (list1 list2)
"Return a new list of distinct elements appearing in both LIST1 and LIST2.
The test for equality is done with `equal', or with `-compare-fn'
if that is non-nil."
(declare (important-return-value t))
(let (test len)
(cond ((null (and list1 list2)) ())
;; Use a hash table if `-compare-fn' is a known hash table
;; test function and either list is long enough.
((and (setq test (dash--hash-test-fn))
(> (setq len (length list2)) dash--short-list-length))
(let ((ht (make-hash-table :test test :size len)))
(--each list2 (puthash it t ht))
;; Remove visited elements to avoid duplicates.
(--filter (when (gethash it ht) (remhash it ht) t) list1)))
((let ((member (dash--member-fn)) intersection)
(--each list1 (and (funcall member it list2)
(not (funcall member it intersection))
(push it intersection)))
(nreverse intersection))))))