From 9726856f297522b1773e8aadaec34dd1a8e68a14 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Sat, 18 Jun 2016 09:32:18 +0200 Subject: 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. --- lisp/emacs-lisp/seq.el | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 166e886fd80..20610a7027d 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -4,7 +4,7 @@ ;; Author: Nicolas Petton ;; 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)) -- cgit v1.2.1