summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/seq.el
diff options
context:
space:
mode:
authorNicolas Petton <nicolas@petton.fr>2016-12-16 11:18:04 +0100
committerNicolas Petton <nicolas@petton.fr>2016-12-16 11:22:00 +0100
commitfb2fdb1435d2520c1cbf2a3d6a53128512a38458 (patch)
tree3c62d01dcc3c4970eb9c8d0caf07a4666a8e3d21 /lisp/emacs-lisp/seq.el
parentcdf5340f51d4346c276102331e3ed29561753b26 (diff)
downloademacs-fb2fdb1435d2520c1cbf2a3d6a53128512a38458.tar.gz
emacs-fb2fdb1435d2520c1cbf2a3d6a53128512a38458.tar.bz2
emacs-fb2fdb1435d2520c1cbf2a3d6a53128512a38458.zip
Make seq-into return the sequence when no conversion needed
* lisp/emacs-lisp/seq.el (seq-into): Do not convert the sequence when no conversion is needed. * test/lisp/emacs-lisp/seq-tests.el (test-seq-into-and-identity): Add a regression test checking for identity.
Diffstat (limited to 'lisp/emacs-lisp/seq.el')
-rw-r--r--lisp/emacs-lisp/seq.el28
1 files changed, 22 insertions, 6 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index 9890e60614e..74510244be7 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -179,9 +179,7 @@ Return a list of the results.
\(fn FUNCTION SEQUENCES...)"
(let ((result nil)
(sequences (seq-map (lambda (s)
- (if (listp s)
- s
- (seq-into s 'list)))
+ (seq-into s 'list))
(cons sequence sequences))))
(while (not (memq nil sequences))
(push (apply function (seq-map #'car sequences)) result)
@@ -275,9 +273,9 @@ of sequence."
TYPE can be one of the following symbols: vector, string or
list."
(pcase type
- (`vector (vconcat sequence))
- (`string (concat sequence))
- (`list (append sequence nil))
+ (`vector (seq--into-vector sequence))
+ (`string (seq--into-string sequence))
+ (`list (seq--into-list sequence))
(_ (error "Not a sequence type name: %S" type))))
(cl-defgeneric seq-filter (pred sequence)
@@ -514,6 +512,24 @@ Signal an error if SEQUENCE is empty."
(null list))
+(defun seq--into-list (sequence)
+ "Concatenate the elements of SEQUENCE into a list."
+ (if (listp sequence)
+ sequence
+ (append sequence nil)))
+
+(defun seq--into-vector (sequence)
+ "Concatenate the elements of SEQUENCE into a vector."
+ (if (vectorp sequence)
+ sequence
+ (vconcat sequence)))
+
+(defun seq--into-string (sequence)
+ "Concatenate the elements of SEQUENCE into a string."
+ (if (stringp sequence)
+ sequence
+ (concat sequence)))
+
(defun seq--activate-font-lock-keywords ()
"Activate font-lock keywords for some symbols defined in seq."
(font-lock-add-keywords 'emacs-lisp-mode