@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
@result{} t
@end group
@group
-(seq-some-p #'numberp [2 4 "6"])
+(seq-some #'numberp [2 4 "6"])
@result{} nil
@end group
@end example
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
(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
(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))
(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))
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)))
"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)
"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)
(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))