>From 7b8d5672db306e3bb52196b04c74eb7098ec32a3 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Thu, 14 Mar 2019 11:19:55 +0000 Subject: [PATCH] Return boolean instead of element in seq-contains * lisp/emacs-lisp/seq.el: Bump major version. (seq-contains): Return non-nil instead of needle if it is found in the sequence. (bug#34852) * test/lisp/emacs-lisp/seq-tests.el (test-seq-contains): Add check for nil as an element. (test-seq-contains-should-return-the-elt): Remove, replacing with... (test-seq-contains-return-non-nil): ...this new test. * doc/lispref/sequences.texi (Sequence Functions): * etc/NEWS: Document change to seq-contains. --- doc/lispref/sequences.texi | 9 +++++---- etc/NEWS | 3 +++ lisp/emacs-lisp/seq.el | 7 +++---- test/lisp/emacs-lisp/seq-tests.el | 9 +++++---- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index 0c3c4e3b28..b0c65fe526 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi @@ -783,14 +783,15 @@ Sequence Functions @defun seq-contains sequence elt &optional function - This function returns the first element in @var{sequence} that is equal to -@var{elt}. If the optional argument @var{function} is non-@code{nil}, -it is a function of two arguments to use instead of the default @code{equal}. + This function returns non-@code{nil} if an element in @var{sequence} +is equal to @var{elt}. If the optional argument @var{function} is +non-@code{nil}, it is a function of two arguments to use instead of +the default @code{equal}. @example @group (seq-contains '(symbol1 symbol2) 'symbol1) -@result{} symbol1 +@result{} t @end group @group (seq-contains '(symbol1 symbol2) 'symbol3) diff --git a/etc/NEWS b/etc/NEWS index 410c1821ae..b41ff89613 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -383,6 +383,9 @@ buffers. New convenience functions 'seq-first' and 'seq-rest' give easy access to respectively the first and all but the first elements of sequences. ++++ +*** 'seq-contains' now returns a boolean rather than the element found. + --- ** Follow mode In the current follow group of windows, "ghost" cursors are no longer diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 4a811d7895..73cb985b85 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -4,7 +4,7 @@ ;; Author: Nicolas Petton ;; Keywords: sequences -;; Version: 2.21 +;; Version: 3.0 ;; Package: seq ;; Maintainer: emacs-devel@gnu.org @@ -356,11 +356,10 @@ seq-sort-by count)) (cl-defgeneric seq-contains (sequence elt &optional testfn) - "Return the first element in SEQUENCE that is equal to ELT. + "Return non-nil if an element in SEQUENCE is equal to ELT. Equality is defined by TESTFN if non-nil or by `equal' if nil." (seq-some (lambda (e) - (when (funcall (or testfn #'equal) elt e) - e)) + (funcall (or testfn #'equal) elt e)) sequence)) (cl-defgeneric seq-set-equal-p (sequence1 sequence2 &optional testfn) diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq-tests.el index d8f00cfea4..fee31e7f8f 100644 --- a/test/lisp/emacs-lisp/seq-tests.el +++ b/test/lisp/emacs-lisp/seq-tests.el @@ -176,14 +176,15 @@ test-sequences-oddp (ert-deftest test-seq-contains () (with-test-sequences (seq '(3 4 5 6)) (should (seq-contains seq 3)) - (should-not (seq-contains seq 7))) + (should-not (seq-contains seq 7)) + (should-not (seq-contains seq nil))) (with-test-sequences (seq '()) (should-not (seq-contains seq 3)) (should-not (seq-contains seq nil)))) -(ert-deftest test-seq-contains-should-return-the-elt () - (with-test-sequences (seq '(3 4 5 6)) - (should (= 5 (seq-contains seq 5))))) +(ert-deftest test-seq-contains-return-non-nil () + (should (seq-contains '(1 2 nil) nil)) + (should (seq-contains [1 2 nil] nil))) (ert-deftest test-seq-every-p () (with-test-sequences (seq '(43 54 22 1)) -- 2.20.1