Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (require 'seq)
- (require 'cl-lib)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (defun seq-intersect-p (first second &rest sequences)
- "Determine if FIRST, SECOND and any of the sequences in SEQUENCES have
- an intersection."
- (if (seq-empty-p sequences)
- (seq-intersection first second)
- (or (seq-intersection first second)
- (apply #'seq-intersect-p
- first
- (seq-first sequences)
- `,@(seq-rest sequences))
- (apply #'seq-intersect-p
- second
- (seq-first sequences)
- `,@(seq-rest sequences))
- (apply #'seq-intersect-p
- (seq-first sequences)
- (seq-elt sequences 2)
- `,@(seq-rest (seq-rest sequences))))))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (progn
- ;;; lists
- (cl-assert (not (seq-intersect-p '()
- '()))
- t
- "Empty lists do not intersect.")
- (cl-assert (not (seq-intersect-p '(1)
- '()))
- t
- "Empty lists do not intersect w/ non-empty lists.")
- (cl-assert (not (seq-intersect-p '(1 2)
- '(3 4)
- '(5 6)))
- t
- "Lists w/ unique elements do not intersect.")
- (cl-assert (seq-intersect-p '(1 2)
- '(3 4)
- '(4))
- t
- "This must have an intersection!")
- (cl-assert (not (seq-intersect-p '(1 1 2)
- '(3 4)
- '(5 6)))
- t
- "Duplicate elements contained to a list should not count towards intersection.")
- ;;; strings
- (cl-assert (not (seq-intersect-p ""
- ""))
- t
- "Empty strings do not intersect.")
- (cl-assert (not (seq-intersect-p "a"
- ""))
- t
- "Empty strings do not intersect w/ non-empty strings.")
- (cl-assert (not (seq-intersect-p "fep"
- "bar"
- "zug"))
- t
- "Strings w/ unique elements do not intersect.")
- (cl-assert (seq-intersect-p "fep"
- "bar"
- "zug"
- "z")
- t
- "This must have an intersection!")
- (cl-assert (not (seq-intersect-p "foo"
- "bar"
- "zug"))
- t
- "Duplicate chars contained to a list should not count towards intersection."))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement