Function: cl-intersection

cl-intersection is an autoloaded and byte-compiled function defined in cl-seq.el.gz.

Signature

(cl-intersection LIST1 LIST2 [KEYWORD VALUE]...)

Documentation

Combine LIST1 and LIST2 using a set-intersection operation.

The resulting list contains all items that appear in both LIST1 and LIST2. This is a non-destructive function; it makes a copy of the data if necessary to avoid corrupting the original LIST1 and LIST2.

Keywords supported: :test :test-not :key

View in manual

Aliases

intersection (obsolete since 27.1)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-seq.el.gz
;;;###autoload
(defun cl-intersection (list1 list2 &rest cl-keys)
  "Combine LIST1 and LIST2 using a set-intersection operation.
The resulting list contains all items that appear in both LIST1 and LIST2.
This is a non-destructive function; it makes a copy of the data if necessary
to avoid corrupting the original LIST1 and LIST2.
\nKeywords supported:  :test :test-not :key
\n(fn LIST1 LIST2 [KEYWORD VALUE]...)"
  (declare (important-return-value t))
  (and list1 list2
       (if (equal list1 list2) list1
	 (cl--parsing-keywords (:key) (:test :test-not)
           (let ((res nil))
             (or (>= (length list1) (length list2))
                 (setq list1 (prog1 list2 (setq list2 list1))))
             (while list2
               (if (if (or cl-keys (numberp (car list2)))
                       (apply #'cl-member (cl--check-key (car list2))
                              list1 cl-keys)
                     (memq (car list2) list1))
                   (push (car list2) res))
               (pop list2))
             res)))))