summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorNicolas Petton <nicolas@petton.fr>2015-08-27 00:21:38 +0200
committerNicolas Petton <nicolas@petton.fr>2015-08-27 00:29:22 +0200
commit259a643d7f7c56976ff794cbdba8f5c70c795091 (patch)
treebb42778be29c91007eae2c7e4f2f4a664fcd950c /lisp/emacs-lisp
parent64fbdc9825ad98ebbc8c021442c1f3c3ba0fd1b1 (diff)
downloademacs-259a643d7f7c56976ff794cbdba8f5c70c795091.tar.gz
emacs-259a643d7f7c56976ff794cbdba8f5c70c795091.tar.bz2
emacs-259a643d7f7c56976ff794cbdba8f5c70c795091.zip
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.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/seq.el13
1 files changed, 12 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index d4a9139758d..a17b0a8f1b9 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.