Rename seq-some-p to seq-some and seq-contains-p to seq-contains
* lisp/emacs-lisp/seq.el (seq-some, seq-contains): Rename the functions without the "-p" prefix. * test/automated/seq-tests.el (test-seq-some, test-seq-contains): Update the tests accordingly. * doc/lispref/sequences.texi (Sequence Functions): Update the documentation for seq.el.
This commit is contained in:
parent
b8147621ec
commit
c36663d866
3 changed files with 30 additions and 30 deletions
|
@ -557,17 +557,17 @@ calling @var{function}.
|
|||
@end example
|
||||
@end defun
|
||||
|
||||
@defun seq-some-p predicate sequence
|
||||
@defun seq-some predicate sequence
|
||||
This function returns the first member of sequence for which @var{predicate}
|
||||
returns non-@code{nil}.
|
||||
|
||||
@example
|
||||
@group
|
||||
(seq-some-p #'numberp ["abc" 1 nil])
|
||||
(seq-some #'numberp ["abc" 1 nil])
|
||||
@result{} 1
|
||||
@end group
|
||||
@group
|
||||
(seq-some-p #'numberp ["abc" "def"])
|
||||
(seq-some #'numberp ["abc" "def"])
|
||||
@result{} nil
|
||||
@end group
|
||||
@end example
|
||||
|
@ -583,7 +583,7 @@ to every element of @var{sequence} returns non-@code{nil}.
|
|||
@result{} t
|
||||
@end group
|
||||
@group
|
||||
(seq-some-p #'numberp [2 4 "6"])
|
||||
(seq-some #'numberp [2 4 "6"])
|
||||
@result{} nil
|
||||
@end group
|
||||
@end example
|
||||
|
@ -621,18 +621,18 @@ according to @var{function}, a function of two arguments that returns
|
|||
non-@code{nil} if the first argument should sort before the second.
|
||||
@end defun
|
||||
|
||||
@defun seq-contains-p sequence elt &optional function
|
||||
@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}.
|
||||
|
||||
@example
|
||||
@group
|
||||
(seq-contains-p '(symbol1 symbol2) 'symbol1)
|
||||
(seq-contains '(symbol1 symbol2) 'symbol1)
|
||||
@result{} symbol1
|
||||
@end group
|
||||
@group
|
||||
(seq-contains-p '(symbol1 symbol2) 'symbol3)
|
||||
(seq-contains '(symbol1 symbol2) 'symbol3)
|
||||
@result{} nil
|
||||
@end group
|
||||
@end example
|
||||
|
|
|
@ -252,14 +252,6 @@ If SEQ is empty, return INITIAL-VALUE and FUNCTION is not called."
|
|||
(setq acc (funcall function acc elt)))
|
||||
acc)))
|
||||
|
||||
(cl-defgeneric seq-some-p (pred seq)
|
||||
"Return any element for which (PRED element) is non-nil in SEQ, nil otherwise."
|
||||
(catch 'seq--break
|
||||
(seq-doseq (elt seq)
|
||||
(when (funcall pred elt)
|
||||
(throw 'seq--break elt)))
|
||||
nil))
|
||||
|
||||
(cl-defgeneric seq-every-p (pred seq)
|
||||
"Return non-nil if (PRED element) is non-nil for all elements of the sequence SEQ."
|
||||
(catch 'seq--break
|
||||
|
@ -268,6 +260,14 @@ If SEQ is empty, return INITIAL-VALUE and FUNCTION is not called."
|
|||
(throw 'seq--break nil)))
|
||||
t))
|
||||
|
||||
(cl-defgeneric seq-some (pred seq)
|
||||
"Return any element for which (PRED element) is non-nil in SEQ, nil otherwise."
|
||||
(catch 'seq--break
|
||||
(seq-doseq (elt seq)
|
||||
(when (funcall pred elt)
|
||||
(throw 'seq--break elt)))
|
||||
nil))
|
||||
|
||||
(cl-defgeneric seq-count (pred seq)
|
||||
"Return the number of elements for which (PRED element) is non-nil in SEQ."
|
||||
(let ((count 0))
|
||||
|
@ -276,10 +276,10 @@ If SEQ is empty, return INITIAL-VALUE and FUNCTION is not called."
|
|||
(setq count (+ 1 count))))
|
||||
count))
|
||||
|
||||
(cl-defgeneric seq-contains-p (seq elt &optional testfn)
|
||||
(cl-defgeneric seq-contains (seq elt &optional testfn)
|
||||
"Return the first element in SEQ that equals to ELT.
|
||||
Equality is defined by TESTFN if non-nil or by `equal' if nil."
|
||||
(seq-some-p (lambda (e)
|
||||
(seq-some (lambda (e)
|
||||
(funcall (or testfn #'equal) elt e))
|
||||
seq))
|
||||
|
||||
|
@ -288,7 +288,7 @@ Equality is defined by TESTFN if non-nil or by `equal' if nil."
|
|||
TESTFN is used to compare elements, or `equal' if TESTFN is nil."
|
||||
(let ((result '()))
|
||||
(seq-doseq (elt seq)
|
||||
(unless (seq-contains-p result elt testfn)
|
||||
(unless (seq-contains result elt testfn)
|
||||
(setq result (cons elt result))))
|
||||
(nreverse result)))
|
||||
|
||||
|
@ -313,7 +313,7 @@ negative integer or 0, nil is returned."
|
|||
"Return a list of the elements that appear in both SEQ1 and SEQ2.
|
||||
Equality is defined by TESTFN if non-nil or by `equal' if nil."
|
||||
(seq-reduce (lambda (acc elt)
|
||||
(if (seq-contains-p seq2 elt testfn)
|
||||
(if (seq-contains seq2 elt testfn)
|
||||
(cons elt acc)
|
||||
acc))
|
||||
(seq-reverse seq1)
|
||||
|
@ -323,7 +323,7 @@ Equality is defined by TESTFN if non-nil or by `equal' if nil."
|
|||
"Return a list of the elements that appear in SEQ1 but not in SEQ2.
|
||||
Equality is defined by TESTFN if non-nil or by `equal' if nil."
|
||||
(seq-reduce (lambda (acc elt)
|
||||
(if (not (seq-contains-p seq2 elt testfn))
|
||||
(if (not (seq-contains seq2 elt testfn))
|
||||
(cons elt acc)
|
||||
acc))
|
||||
(seq-reverse seq1)
|
||||
|
|
|
@ -129,21 +129,21 @@ Evaluate BODY for each created sequence.
|
|||
(should (eq (seq-reduce #'+ seq 0) 0))
|
||||
(should (eq (seq-reduce #'+ seq 7) 7))))
|
||||
|
||||
(ert-deftest test-seq-some-p ()
|
||||
(ert-deftest test-seq-some ()
|
||||
(with-test-sequences (seq '(4 3 2 1))
|
||||
(should (= (seq-some-p #'test-sequences-evenp seq) 4))
|
||||
(should (= (seq-some-p #'test-sequences-oddp seq) 3))
|
||||
(should-not (seq-some-p (lambda (elt) (> elt 10)) seq)))
|
||||
(should (= (seq-some #'test-sequences-evenp seq) 4))
|
||||
(should (= (seq-some #'test-sequences-oddp seq) 3))
|
||||
(should-not (seq-some (lambda (elt) (> elt 10)) seq)))
|
||||
(with-test-sequences (seq '())
|
||||
(should-not (seq-some-p #'test-sequences-oddp seq))))
|
||||
(should-not (seq-some #'test-sequences-oddp seq))))
|
||||
|
||||
(ert-deftest test-seq-contains-p ()
|
||||
(ert-deftest test-seq-contains ()
|
||||
(with-test-sequences (seq '(3 4 5 6))
|
||||
(should (seq-contains-p seq 3))
|
||||
(should-not (seq-contains-p seq 7)))
|
||||
(should (seq-contains seq 3))
|
||||
(should-not (seq-contains seq 7)))
|
||||
(with-test-sequences (seq '())
|
||||
(should-not (seq-contains-p seq 3))
|
||||
(should-not (seq-contains-p seq nil))))
|
||||
(should-not (seq-contains seq 3))
|
||||
(should-not (seq-contains seq nil))))
|
||||
|
||||
(ert-deftest test-seq-every-p ()
|
||||
(with-test-sequences (seq '(43 54 22 1))
|
||||
|
|
Loading…
Add table
Reference in a new issue