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.
This commit is contained in:
Nicolas Petton 2016-12-16 11:18:04 +01:00
parent cdf5340f51
commit fb2fdb1435
2 changed files with 30 additions and 6 deletions

View file

@ -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