[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 259a643: Improve seq-concatenate for new sequence t
From: |
Nicolas Petton |
Subject: |
[Emacs-diffs] master 259a643: Improve seq-concatenate for new sequence types |
Date: |
Wed, 26 Aug 2015 22:29:30 +0000 |
branch: master
commit 259a643d7f7c56976ff794cbdba8f5c70c795091
Author: Nicolas Petton <address@hidden>
Commit: Nicolas Petton <address@hidden>
Improve seq-concatenate for new sequence types
Use the new `seq-into-sequence' in seqs passed to `seq-concatenate' to
ensure that concatenation happens on sequences only. This makes it
possible to use `seq-concatenate' for new types of seqs.
* lisp/emacs-lisp/seq.el (seq-into-sequence, seq-concatenate): New
function used in `seq-concatenate'.
* test/automated/seq-tests.el (test-seq-into-sequence): New unit test
for seq-into-sequence.
---
lisp/emacs-lisp/seq.el | 13 ++++++++++++-
test/automated/seq-tests.el | 5 +++++
2 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index d4a9139..a17b0a8 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -48,6 +48,7 @@
;; - `seq-do'
;; - `seq-p'
;; - `seq-subseq'
+;; - `seq-into-sequence'
;; - `seq-copy'
;; - `seq-into'
;;
@@ -200,7 +201,17 @@ The result is a sequence of the same type as SEQ."
TYPE must be one of following symbols: vector, string or list.
\n(fn TYPE SEQUENCE...)"
- (apply #'cl-concatenate type seqs))
+ (apply #'cl-concatenate type (seq-map #'seq-into-sequence seqs)))
+
+(cl-defgeneric seq-into-sequence (seq)
+ "Convert SEQ into a sequence.
+
+The default implementation is to signal an error if SEQ is not a
+sequence, specific functions should be implemented for new types
+of seq."
+ (unless (sequencep seq)
+ (error "Cannot convert %S into a sequence" seq))
+ seq)
(cl-defgeneric seq-into (seq type)
"Convert the sequence SEQ into a sequence of type TYPE.
diff --git a/test/automated/seq-tests.el b/test/automated/seq-tests.el
index 163935b..482daee 100644
--- a/test/automated/seq-tests.el
+++ b/test/automated/seq-tests.el
@@ -312,5 +312,10 @@ Evaluate BODY for each created sequence.
(should (= (seq-min seq) 0))
(should (= (seq-max seq) 5))))
+(ert-deftest test-seq-into-sequence ()
+ (with-test-sequences (seq '(1 2 3))
+ (should (eq seq (seq-into-sequence seq)))
+ (should-error (seq-into-sequence 2))))
+
(provide 'seq-tests)
;;; seq-tests.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 259a643: Improve seq-concatenate for new sequence types,
Nicolas Petton <=