summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/seq.el
diff options
context:
space:
mode:
authorK. Handa <handa@gnu.org>2015-09-27 17:06:12 +0900
committerK. Handa <handa@gnu.org>2015-09-27 17:06:12 +0900
commit52beda922d2cb523a03661bf74b8678c8b45e440 (patch)
tree04617b37298746a61d5324a5b35c9b71f439d762 /lisp/emacs-lisp/seq.el
parent94ed5167557112fb00eeca05e62589db744206de (diff)
parent1ac5a9c20cb22efb398fa18781c6b932dd4e54df (diff)
downloademacs-52beda922d2cb523a03661bf74b8678c8b45e440.tar.gz
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
Diffstat (limited to 'lisp/emacs-lisp/seq.el')
-rw-r--r--lisp/emacs-lisp/seq.el21
1 files changed, 14 insertions, 7 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index 8dc91471312..e0f17c0335d 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -270,6 +270,19 @@ If so, return the non-nil value returned by PRED."
(throw 'seq--break result))))
nil))
+(cl-defgeneric seq-find (pred seq &optional default)
+ "Return the first element for which (PRED element) is non-nil in SEQ.
+If no element is found, return DEFAULT.
+
+Note that `seq-find' has an ambiguity if the found element is
+identical to DEFAULT, as it cannot be known if an element was
+found or not."
+ (catch 'seq--break
+ (seq-doseq (elt seq)
+ (when (funcall pred elt)
+ (throw 'seq--break elt)))
+ default))
+
(cl-defgeneric seq-count (pred seq)
"Return the number of elements for which (PRED element) is non-nil in SEQ."
(let ((count 0))
@@ -417,13 +430,7 @@ If no element is found, return nil."
(nreverse result)))
(cl-defmethod seq-drop-while (pred (list list))
- "Optimized implementation of `seq-drop-while' for lists"
- (while (and list (funcall pred (car list)))
- (setq list (cdr list)))
- list)
-
-(cl-defmethod seq-drop-while (pred (list list))
- "Optimized implementation of `seq-drop-while' for lists"
+ "Optimized implementation of `seq-drop-while' for lists."
(while (and list (funcall pred (car list)))
(setq list (cdr list)))
list)