Add seq-do-indexed
* lisp/emacs-lisp/seq.el (seq-do-indexed): New function. * test/lisp/emacs-lisp/seq-tests.el: Add a unit test for seq-do-indexed.
This commit is contained in:
parent
44eca25a4b
commit
9726856f29
2 changed files with 26 additions and 1 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
;; Author: Nicolas Petton <nicolas@petton.fr>
|
||||
;; Keywords: sequences
|
||||
;; Version: 2.16
|
||||
;; Version: 2.17
|
||||
;; Package: seq
|
||||
|
||||
;; Maintainer: emacs-devel@gnu.org
|
||||
|
@ -117,6 +117,16 @@ Return SEQUENCE."
|
|||
|
||||
(defalias 'seq-each #'seq-do)
|
||||
|
||||
(defun seq-do-indexed (function sequence)
|
||||
"Apply FUNCTION to each element of SEQUENCE and return nil.
|
||||
Unlike `seq-map', FUNCTION takes two arguments: the element of
|
||||
the sequence, and its index within the sequence."
|
||||
(let ((index 0))
|
||||
(seq-do (lambda (elt)
|
||||
(funcall function elt index)
|
||||
(setq index (1+ index)))
|
||||
sequence)))
|
||||
|
||||
(cl-defgeneric seqp (sequence)
|
||||
"Return non-nil if SEQUENCE is a sequence, nil otherwise."
|
||||
(sequencep sequence))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue