aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorNicolas Petton2015-09-06 00:26:17 +0200
committerNicolas Petton2015-09-06 00:44:39 +0200
commitaeb1d6bdd54671a2e2b7dfbd22fcfe1aa19b36d1 (patch)
tree117e8f076fe9edb808781730f09122403855313d /lisp
parentc36663d866e64fcb4b0d94742009d84366e9b54f (diff)
downloademacs-aeb1d6bdd54671a2e2b7dfbd22fcfe1aa19b36d1.tar.gz
emacs-aeb1d6bdd54671a2e2b7dfbd22fcfe1aa19b36d1.zip
Improve the semantic of seq-some
Update seq-some to return non-nil if the predicate returns non-nil for any element of the seq, in which case the returned value is the one returned by the predicate. * lisp/emacs-lisp/seq.el (seq-some): Update the function and its docstring. * test/automated/seq-tests.el (test-seq-some): Add a regression test. * doc/lispref/sequences.texi (Sequence Functions): Update the documentation for seq-some.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/emacs-lisp/seq.el12
1 files changed, 7 insertions, 5 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index bf5495baac3..8dc91471312 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -261,11 +261,13 @@ If SEQ is empty, return INITIAL-VALUE and FUNCTION is not called."
261 t)) 261 t))
262 262
263(cl-defgeneric seq-some (pred seq) 263(cl-defgeneric seq-some (pred seq)
264 "Return any element for which (PRED element) is non-nil in SEQ, nil otherwise." 264 "Return non-nil if (PRED element) is non-nil for any element in SEQ, nil otherwise.
265If so, return the non-nil value returned by PRED."
265 (catch 'seq--break 266 (catch 'seq--break
266 (seq-doseq (elt seq) 267 (seq-doseq (elt seq)
267 (when (funcall pred elt) 268 (let ((result (funcall pred elt)))
268 (throw 'seq--break elt))) 269 (when result
270 (throw 'seq--break result))))
269 nil)) 271 nil))
270 272
271(cl-defgeneric seq-count (pred seq) 273(cl-defgeneric seq-count (pred seq)
@@ -280,8 +282,8 @@ If SEQ is empty, return INITIAL-VALUE and FUNCTION is not called."
280 "Return the first element in SEQ that equals to ELT. 282 "Return the first element in SEQ that equals to ELT.
281Equality is defined by TESTFN if non-nil or by `equal' if nil." 283Equality is defined by TESTFN if non-nil or by `equal' if nil."
282 (seq-some (lambda (e) 284 (seq-some (lambda (e)
283 (funcall (or testfn #'equal) elt e)) 285 (funcall (or testfn #'equal) elt e))
284 seq)) 286 seq))
285 287
286(cl-defgeneric seq-uniq (seq &optional testfn) 288(cl-defgeneric seq-uniq (seq &optional testfn)
287 "Return a list of the elements of SEQ with duplicates removed. 289 "Return a list of the elements of SEQ with duplicates removed.