aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Malabarba2015-10-28 14:27:39 +0000
committerArtur Malabarba2015-10-28 15:40:23 +0000
commit7dfe247864f12b93b906edb5934af3c356acade4 (patch)
tree49ecd679906aae8113b8381fe93b91ddde51b648
parent4281f722dd782d91f4b2bbd03834cbd1d944db5c (diff)
downloademacs-7dfe247864f12b93b906edb5934af3c356acade4.tar.gz
emacs-7dfe247864f12b93b906edb5934af3c356acade4.zip
* lisp/emacs-lisp/seq.el (seq-mapn): New function
* doc/lispref/sequences.texi (Sequence Functions): Document seq-mapn
-rw-r--r--doc/lispref/sequences.texi18
-rw-r--r--lisp/emacs-lisp/seq.el17
2 files changed, 34 insertions, 1 deletions
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index 8ecae7b58b5..730dac10452 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.
572@end example 572@end example
573@end defun 573@end defun
574 574
575@defun seq-mapn function &rest sequences
576 This function returns the result of applying @var{function} to each
577element of @var{sequences}. The arity of @var{function} must match
578the number of sequences. Mapping stops at the shrotest sequence, and
579the returned value is a list.
580
581@example
582@group
583(seq-mapn #'+ '(2 4 6) '(20 40 60))
584@result{} (22 44 66)
585@end group
586@group
587(seq-mapn #'concat '("moskito" "bite") ["bee" "sting"])
588@result{} ("moskitobee" "bitesting")
589@end group
590@end example
591@end defun
592
575@defun seq-filter predicate sequence 593@defun seq-filter predicate sequence
576@cindex filtering sequences 594@cindex filtering sequences
577 This function returns a list of all the elements in @var{sequence} 595 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 d0c2d24b015..68265094c17 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -4,7 +4,7 @@
4 4
5;; Author: Nicolas Petton <nicolas@petton.fr> 5;; Author: Nicolas Petton <nicolas@petton.fr>
6;; Keywords: sequences 6;; Keywords: sequences
7;; Version: 2.1 7;; Version: 2.2
8;; Package: seq 8;; Package: seq
9 9
10;; Maintainer: emacs-devel@gnu.org 10;; Maintainer: emacs-devel@gnu.org
@@ -148,6 +148,21 @@ if positive or too small if negative)."
148(cl-defmethod seq-map (function (sequence sequence)) 148(cl-defmethod seq-map (function (sequence sequence))
149 (mapcar function sequence)) 149 (mapcar function sequence))
150 150
151(cl-defgeneric seq-mapn (function sequence &rest sequences)
152 "Like `seq-map' but FUNCTION is mapped over all SEQUENCES.
153The arity of FUNCTION must match the number of SEQUENCES, and the
154mapping stops on the shortest sequence.
155Return a list of the results.
156
157\(fn FUNCTION SEQUENCES...)"
158 (let ((result nil)
159 (sequences (seq-map (lambda (s) (seq-into s 'list))
160 (cons sequence sequences))))
161 (while (not (memq nil sequences))
162 (push (apply function (seq-map #'car sequences)) result)
163 (setq sequences (seq-map #'cdr sequences)))
164 (nreverse result)))
165
151(cl-defgeneric seq-drop (sequence n) 166(cl-defgeneric seq-drop (sequence n)
152 "Remove the first N elements of SEQUENCE and return the result. 167 "Remove the first N elements of SEQUENCE and return the result.
153The result is a sequence of the same type as SEQUENCE. 168The result is a sequence of the same type as SEQUENCE.