aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Petton2015-09-06 00:05:52 +0200
committerNicolas Petton2015-09-06 00:05:52 +0200
commitc36663d866e64fcb4b0d94742009d84366e9b54f (patch)
tree6ff19468ec463376c8ef05f14923c4220f0247b5
parentb8147621ec91e1ce8e34d55141bb75921dbfc080 (diff)
downloademacs-c36663d866e64fcb4b0d94742009d84366e9b54f.tar.gz
emacs-c36663d866e64fcb4b0d94742009d84366e9b54f.zip
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.
-rw-r--r--doc/lispref/sequences.texi14
-rw-r--r--lisp/emacs-lisp/seq.el26
-rw-r--r--test/automated/seq-tests.el20
3 files changed, 30 insertions, 30 deletions
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index 12ed881dadb..22ae9959602 100644
--- a/doc/lispref/sequences.texi
+++ b/doc/lispref/sequences.texi
@@ -557,17 +557,17 @@ calling @var{function}.
557@end example 557@end example
558@end defun 558@end defun
559 559
560@defun seq-some-p predicate sequence 560@defun seq-some predicate sequence
561 This function returns the first member of sequence for which @var{predicate} 561 This function returns the first member of sequence for which @var{predicate}
562returns non-@code{nil}. 562returns non-@code{nil}.
563 563
564@example 564@example
565@group 565@group
566(seq-some-p #'numberp ["abc" 1 nil]) 566(seq-some #'numberp ["abc" 1 nil])
567@result{} 1 567@result{} 1
568@end group 568@end group
569@group 569@group
570(seq-some-p #'numberp ["abc" "def"]) 570(seq-some #'numberp ["abc" "def"])
571@result{} nil 571@result{} nil
572@end group 572@end group
573@end example 573@end example
@@ -583,7 +583,7 @@ to every element of @var{sequence} returns non-@code{nil}.
583@result{} t 583@result{} t
584@end group 584@end group
585@group 585@group
586(seq-some-p #'numberp [2 4 "6"]) 586(seq-some #'numberp [2 4 "6"])
587@result{} nil 587@result{} nil
588@end group 588@end group
589@end example 589@end example
@@ -621,18 +621,18 @@ according to @var{function}, a function of two arguments that returns
621non-@code{nil} if the first argument should sort before the second. 621non-@code{nil} if the first argument should sort before the second.
622@end defun 622@end defun
623 623
624@defun seq-contains-p sequence elt &optional function 624@defun seq-contains sequence elt &optional function
625 This function returns the first element in @var{sequence} that is equal to 625 This function returns the first element in @var{sequence} that is equal to
626@var{elt}. If the optional argument @var{function} is non-@code{nil}, 626@var{elt}. If the optional argument @var{function} is non-@code{nil},
627it is a function of two arguments to use instead of the default @code{equal}. 627it is a function of two arguments to use instead of the default @code{equal}.
628 628
629@example 629@example
630@group 630@group
631(seq-contains-p '(symbol1 symbol2) 'symbol1) 631(seq-contains '(symbol1 symbol2) 'symbol1)
632@result{} symbol1 632@result{} symbol1
633@end group 633@end group
634@group 634@group
635(seq-contains-p '(symbol1 symbol2) 'symbol3) 635(seq-contains '(symbol1 symbol2) 'symbol3)
636@result{} nil 636@result{} nil
637@end group 637@end group
638@end example 638@end example
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index a17b0a8f1b9..bf5495baac3 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -252,14 +252,6 @@ If SEQ is empty, return INITIAL-VALUE and FUNCTION is not called."
252 (setq acc (funcall function acc elt))) 252 (setq acc (funcall function acc elt)))
253 acc))) 253 acc)))
254 254
255(cl-defgeneric seq-some-p (pred seq)
256 "Return any element for which (PRED element) is non-nil in SEQ, nil otherwise."
257 (catch 'seq--break
258 (seq-doseq (elt seq)
259 (when (funcall pred elt)
260 (throw 'seq--break elt)))
261 nil))
262
263(cl-defgeneric seq-every-p (pred seq) 255(cl-defgeneric seq-every-p (pred seq)
264 "Return non-nil if (PRED element) is non-nil for all elements of the sequence SEQ." 256 "Return non-nil if (PRED element) is non-nil for all elements of the sequence SEQ."
265 (catch 'seq--break 257 (catch 'seq--break
@@ -268,6 +260,14 @@ If SEQ is empty, return INITIAL-VALUE and FUNCTION is not called."
268 (throw 'seq--break nil))) 260 (throw 'seq--break nil)))
269 t)) 261 t))
270 262
263(cl-defgeneric seq-some (pred seq)
264 "Return any element for which (PRED element) is non-nil in SEQ, nil otherwise."
265 (catch 'seq--break
266 (seq-doseq (elt seq)
267 (when (funcall pred elt)
268 (throw 'seq--break elt)))
269 nil))
270
271(cl-defgeneric seq-count (pred seq) 271(cl-defgeneric seq-count (pred seq)
272 "Return the number of elements for which (PRED element) is non-nil in SEQ." 272 "Return the number of elements for which (PRED element) is non-nil in SEQ."
273 (let ((count 0)) 273 (let ((count 0))
@@ -276,10 +276,10 @@ If SEQ is empty, return INITIAL-VALUE and FUNCTION is not called."
276 (setq count (+ 1 count)))) 276 (setq count (+ 1 count))))
277 count)) 277 count))
278 278
279(cl-defgeneric seq-contains-p (seq elt &optional testfn) 279(cl-defgeneric seq-contains (seq elt &optional testfn)
280 "Return the first element in SEQ that equals to ELT. 280 "Return the first element in SEQ that equals to ELT.
281Equality is defined by TESTFN if non-nil or by `equal' if nil." 281Equality is defined by TESTFN if non-nil or by `equal' if nil."
282 (seq-some-p (lambda (e) 282 (seq-some (lambda (e)
283 (funcall (or testfn #'equal) elt e)) 283 (funcall (or testfn #'equal) elt e))
284 seq)) 284 seq))
285 285
@@ -288,7 +288,7 @@ Equality is defined by TESTFN if non-nil or by `equal' if nil."
288TESTFN is used to compare elements, or `equal' if TESTFN is nil." 288TESTFN is used to compare elements, or `equal' if TESTFN is nil."
289 (let ((result '())) 289 (let ((result '()))
290 (seq-doseq (elt seq) 290 (seq-doseq (elt seq)
291 (unless (seq-contains-p result elt testfn) 291 (unless (seq-contains result elt testfn)
292 (setq result (cons elt result)))) 292 (setq result (cons elt result))))
293 (nreverse result))) 293 (nreverse result)))
294 294
@@ -313,7 +313,7 @@ negative integer or 0, nil is returned."
313 "Return a list of the elements that appear in both SEQ1 and SEQ2. 313 "Return a list of the elements that appear in both SEQ1 and SEQ2.
314Equality is defined by TESTFN if non-nil or by `equal' if nil." 314Equality is defined by TESTFN if non-nil or by `equal' if nil."
315 (seq-reduce (lambda (acc elt) 315 (seq-reduce (lambda (acc elt)
316 (if (seq-contains-p seq2 elt testfn) 316 (if (seq-contains seq2 elt testfn)
317 (cons elt acc) 317 (cons elt acc)
318 acc)) 318 acc))
319 (seq-reverse seq1) 319 (seq-reverse seq1)
@@ -323,7 +323,7 @@ Equality is defined by TESTFN if non-nil or by `equal' if nil."
323 "Return a list of the elements that appear in SEQ1 but not in SEQ2. 323 "Return a list of the elements that appear in SEQ1 but not in SEQ2.
324Equality is defined by TESTFN if non-nil or by `equal' if nil." 324Equality is defined by TESTFN if non-nil or by `equal' if nil."
325 (seq-reduce (lambda (acc elt) 325 (seq-reduce (lambda (acc elt)
326 (if (not (seq-contains-p seq2 elt testfn)) 326 (if (not (seq-contains seq2 elt testfn))
327 (cons elt acc) 327 (cons elt acc)
328 acc)) 328 acc))
329 (seq-reverse seq1) 329 (seq-reverse seq1)
diff --git a/test/automated/seq-tests.el b/test/automated/seq-tests.el
index 482daeecb98..efbb90dd988 100644
--- a/test/automated/seq-tests.el
+++ b/test/automated/seq-tests.el
@@ -129,21 +129,21 @@ Evaluate BODY for each created sequence.
129 (should (eq (seq-reduce #'+ seq 0) 0)) 129 (should (eq (seq-reduce #'+ seq 0) 0))
130 (should (eq (seq-reduce #'+ seq 7) 7)))) 130 (should (eq (seq-reduce #'+ seq 7) 7))))
131 131
132(ert-deftest test-seq-some-p () 132(ert-deftest test-seq-some ()
133 (with-test-sequences (seq '(4 3 2 1)) 133 (with-test-sequences (seq '(4 3 2 1))
134 (should (= (seq-some-p #'test-sequences-evenp seq) 4)) 134 (should (= (seq-some #'test-sequences-evenp seq) 4))
135 (should (= (seq-some-p #'test-sequences-oddp seq) 3)) 135 (should (= (seq-some #'test-sequences-oddp seq) 3))
136 (should-not (seq-some-p (lambda (elt) (> elt 10)) seq))) 136 (should-not (seq-some (lambda (elt) (> elt 10)) seq)))
137 (with-test-sequences (seq '()) 137 (with-test-sequences (seq '())
138 (should-not (seq-some-p #'test-sequences-oddp seq)))) 138 (should-not (seq-some #'test-sequences-oddp seq))))
139 139
140(ert-deftest test-seq-contains-p () 140(ert-deftest test-seq-contains ()
141 (with-test-sequences (seq '(3 4 5 6)) 141 (with-test-sequences (seq '(3 4 5 6))
142 (should (seq-contains-p seq 3)) 142 (should (seq-contains seq 3))
143 (should-not (seq-contains-p seq 7))) 143 (should-not (seq-contains seq 7)))
144 (with-test-sequences (seq '()) 144 (with-test-sequences (seq '())
145 (should-not (seq-contains-p seq 3)) 145 (should-not (seq-contains seq 3))
146 (should-not (seq-contains-p seq nil)))) 146 (should-not (seq-contains seq nil))))
147 147
148(ert-deftest test-seq-every-p () 148(ert-deftest test-seq-every-p ()
149 (with-test-sequences (seq '(43 54 22 1)) 149 (with-test-sequences (seq '(43 54 22 1))