emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 7dfe247 4/4: * lisp/emacs-lisp/seq.el (seq-mapn): N


From: Artur Malabarba
Subject: [Emacs-diffs] master 7dfe247 4/4: * lisp/emacs-lisp/seq.el (seq-mapn): New function
Date: Wed, 28 Oct 2015 15:41:07 +0000

branch: master
commit 7dfe247864f12b93b906edb5934af3c356acade4
Author: Artur Malabarba <address@hidden>
Commit: Artur Malabarba <address@hidden>

    * lisp/emacs-lisp/seq.el (seq-mapn): New function
    
    * doc/lispref/sequences.texi (Sequence Functions): Document seq-mapn
---
 doc/lispref/sequences.texi |   18 ++++++++++++++++++
 lisp/emacs-lisp/seq.el     |   17 ++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index 8ecae7b..730dac1 100644
--- a/doc/lispref/sequences.texi
+++ b/doc/lispref/sequences.texi
@@ -572,6 +572,24 @@ element of @var{sequence}.  The returned value is a list.
 @end example
 @end defun
 
address@hidden seq-mapn function &rest sequences
+  This function returns the result of applying @var{function} to each
+element of @var{sequences}.  The arity of @var{function} must match
+the number of sequences.  Mapping stops at the shrotest sequence, and
+the returned value is a list.
+
address@hidden
address@hidden
+(seq-mapn #'+ '(2 4 6) '(20 40 60))
address@hidden (22 44 66)
address@hidden group
address@hidden
+(seq-mapn #'concat '("moskito" "bite") ["bee" "sting"])
address@hidden ("moskitobee" "bitesting")
address@hidden group
address@hidden example
address@hidden defun
+
 @defun seq-filter predicate sequence
 @cindex filtering sequences
   This function returns a list of all the elements in @var{sequence}
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index d0c2d24..6826509 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -4,7 +4,7 @@
 
 ;; Author: Nicolas Petton <address@hidden>
 ;; Keywords: sequences
-;; Version: 2.1
+;; Version: 2.2
 ;; Package: seq
 
 ;; Maintainer: address@hidden
@@ -148,6 +148,21 @@ if positive or too small if negative)."
 (cl-defmethod seq-map (function (sequence sequence))
   (mapcar function sequence))
 
+(cl-defgeneric seq-mapn (function sequence &rest sequences)
+  "Like `seq-map' but FUNCTION is mapped over all SEQUENCES.
+The arity of FUNCTION must match the number of SEQUENCES, and the
+mapping stops on the shortest sequence.
+Return a list of the results.
+
+\(fn FUNCTION SEQUENCES...)"
+  (let ((result nil)
+        (sequences (seq-map (lambda (s) (seq-into s 'list))
+                            (cons sequence sequences))))
+    (while (not (memq nil sequences))
+      (push (apply function (seq-map #'car sequences)) result)
+      (setq sequences (seq-map #'cdr sequences)))
+    (nreverse result)))
+
 (cl-defgeneric seq-drop (sequence n)
   "Remove the first N elements of SEQUENCE and return the result.
 The result is a sequence of the same type as SEQUENCE.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]