diff options
author | Nicolas Petton <nicolas@petton.fr> | 2015-09-06 00:26:17 +0200 |
---|---|---|
committer | Nicolas Petton <nicolas@petton.fr> | 2015-09-06 00:44:39 +0200 |
commit | aeb1d6bdd54671a2e2b7dfbd22fcfe1aa19b36d1 (patch) | |
tree | 117e8f076fe9edb808781730f09122403855313d /lisp/emacs-lisp/seq.el | |
parent | c36663d866e64fcb4b0d94742009d84366e9b54f (diff) | |
download | emacs-aeb1d6bdd54671a2e2b7dfbd22fcfe1aa19b36d1.tar.gz |
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/emacs-lisp/seq.el')
-rw-r--r-- | lisp/emacs-lisp/seq.el | 12 |
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." t)) (cl-defgeneric seq-some (pred seq) - "Return any element for which (PRED element) is non-nil in SEQ, nil otherwise." + "Return non-nil if (PRED element) is non-nil for any element in SEQ, nil otherwise. +If so, return the non-nil value returned by PRED." (catch 'seq--break (seq-doseq (elt seq) - (when (funcall pred elt) - (throw 'seq--break elt))) + (let ((result (funcall pred elt))) + (when result + (throw 'seq--break result)))) nil)) (cl-defgeneric seq-count (pred seq) @@ -280,8 +282,8 @@ If SEQ is empty, return INITIAL-VALUE and FUNCTION is not called." "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 (lambda (e) - (funcall (or testfn #'equal) elt e)) - seq)) + (funcall (or testfn #'equal) elt e)) + seq)) (cl-defgeneric seq-uniq (seq &optional testfn) "Return a list of the elements of SEQ with duplicates removed. |