[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 2122486: Backport the latest changes to seq.el from Emacs
From: |
Nicolas Petton |
Subject: |
[elpa] master 2122486: Backport the latest changes to seq.el from Emacs master |
Date: |
Fri, 16 Dec 2016 10:31:15 +0000 (UTC) |
branch: master
commit 212248625c5e5a5b6bee20f9755288ff01e4f59f
Author: Nicolas Petton <address@hidden>
Commit: Nicolas Petton <address@hidden>
Backport the latest changes to seq.el from Emacs master
* packages/seq/seq-24.el:
* packages/seq/seq-25.el (seq-into): Do not convert the sequence if not
needed.
* packages/seq/tests/seq-tests.el: Add a regression test.
---
packages/seq/seq-24.el | 28 ++++++++++++++++++++++------
packages/seq/seq-25.el | 28 ++++++++++++++++++++++------
packages/seq/tests/seq-tests.el | 8 ++++++++
3 files changed, 52 insertions(+), 12 deletions(-)
diff --git a/packages/seq/seq-24.el b/packages/seq/seq-24.el
index 36a3f2b..89c70a6 100644
--- a/packages/seq/seq-24.el
+++ b/packages/seq/seq-24.el
@@ -287,9 +287,7 @@ Return a list of the results.
\(fn FUNCTION SEQS...)"
(let ((result nil)
(seqs (seq-map (lambda (s)
- (if (listp s)
- s
- (seq-into s 'list)))
+ (seq-into s 'list))
(cons sequence seqs))))
(while (not (memq nil seqs))
(push (apply function (seq-map #'car seqs)) result)
@@ -359,9 +357,9 @@ See also the function `nreverse', which is used more often."
"Convert the sequence SEQUENCE into a sequence of type TYPE.
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))))
(defun seq-min (sequence)
@@ -465,6 +463,24 @@ If no element is found, return nil."
(defalias 'seq-map #'mapcar)
(defalias 'seqp #'sequencep)
+(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)))
+
(unless (fboundp 'elisp--font-lock-flush-elisp-buffers)
;; In Emacsā„25, (via elisp--font-lock-flush-elisp-buffers and a few others)
;; we automatically highlight macros.
diff --git a/packages/seq/seq-25.el b/packages/seq/seq-25.el
index ff79dc0..d503be8 100644
--- a/packages/seq/seq-25.el
+++ b/packages/seq/seq-25.el
@@ -172,9 +172,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)
@@ -268,9 +266,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)
@@ -464,6 +462,24 @@ SEQUENCE must be a sequence of numbers or markers."
(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--make-pcase-bindings (args)
"Return a list of bindings of the variables in ARGS to the elements of a
sequence."
(let ((bindings '())
diff --git a/packages/seq/tests/seq-tests.el b/packages/seq/tests/seq-tests.el
index b0d2931..d53fa36 100644
--- a/packages/seq/tests/seq-tests.el
+++ b/packages/seq/tests/seq-tests.el
@@ -370,5 +370,13 @@ Evaluate BODY for each created sequence.
(should (equal (seq-mapn #'+ '(3 4 5 7) l1)
'(4 5 6 8)))))
+(ert-deftest test-seq-into-and-identity ()
+ (let ((lst '(1 2 3))
+ (vec [1 2 3])
+ (str "foo bar"))
+ (should (eq (seq-into lst 'list) lst))
+ (should (eq (seq-into vec 'vector) vec))
+ (should (eq (seq-into str 'string) str))))
+
(provide 'seq-tests)
;;; seq-tests.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] master 2122486: Backport the latest changes to seq.el from Emacs master,
Nicolas Petton <=