diff options
| author | Nicolas Petton | 2015-08-27 00:21:38 +0200 |
|---|---|---|
| committer | Nicolas Petton | 2015-08-27 00:29:22 +0200 |
| commit | 259a643d7f7c56976ff794cbdba8f5c70c795091 (patch) | |
| tree | bb42778be29c91007eae2c7e4f2f4a664fcd950c | |
| parent | 64fbdc9825ad98ebbc8c021442c1f3c3ba0fd1b1 (diff) | |
| download | emacs-259a643d7f7c56976ff794cbdba8f5c70c795091.tar.gz 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.
| -rw-r--r-- | lisp/emacs-lisp/seq.el | 13 | ||||
| -rw-r--r-- | 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 d4a9139758d..a17b0a8f1b9 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el | |||
| @@ -48,6 +48,7 @@ | |||
| 48 | ;; - `seq-do' | 48 | ;; - `seq-do' |
| 49 | ;; - `seq-p' | 49 | ;; - `seq-p' |
| 50 | ;; - `seq-subseq' | 50 | ;; - `seq-subseq' |
| 51 | ;; - `seq-into-sequence' | ||
| 51 | ;; - `seq-copy' | 52 | ;; - `seq-copy' |
| 52 | ;; - `seq-into' | 53 | ;; - `seq-into' |
| 53 | ;; | 54 | ;; |
| @@ -200,7 +201,17 @@ The result is a sequence of the same type as SEQ." | |||
| 200 | TYPE must be one of following symbols: vector, string or list. | 201 | TYPE must be one of following symbols: vector, string or list. |
| 201 | 202 | ||
| 202 | \n(fn TYPE SEQUENCE...)" | 203 | \n(fn TYPE SEQUENCE...)" |
| 203 | (apply #'cl-concatenate type seqs)) | 204 | (apply #'cl-concatenate type (seq-map #'seq-into-sequence seqs))) |
| 205 | |||
| 206 | (cl-defgeneric seq-into-sequence (seq) | ||
| 207 | "Convert SEQ into a sequence. | ||
| 208 | |||
| 209 | The default implementation is to signal an error if SEQ is not a | ||
| 210 | sequence, specific functions should be implemented for new types | ||
| 211 | of seq." | ||
| 212 | (unless (sequencep seq) | ||
| 213 | (error "Cannot convert %S into a sequence" seq)) | ||
| 214 | seq) | ||
| 204 | 215 | ||
| 205 | (cl-defgeneric seq-into (seq type) | 216 | (cl-defgeneric seq-into (seq type) |
| 206 | "Convert the sequence SEQ into a sequence of type TYPE. | 217 | "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 163935b5432..482daeecb98 100644 --- a/test/automated/seq-tests.el +++ b/test/automated/seq-tests.el | |||
| @@ -312,5 +312,10 @@ Evaluate BODY for each created sequence. | |||
| 312 | (should (= (seq-min seq) 0)) | 312 | (should (= (seq-min seq) 0)) |
| 313 | (should (= (seq-max seq) 5)))) | 313 | (should (= (seq-max seq) 5)))) |
| 314 | 314 | ||
| 315 | (ert-deftest test-seq-into-sequence () | ||
| 316 | (with-test-sequences (seq '(1 2 3)) | ||
| 317 | (should (eq seq (seq-into-sequence seq))) | ||
| 318 | (should-error (seq-into-sequence 2)))) | ||
| 319 | |||
| 315 | (provide 'seq-tests) | 320 | (provide 'seq-tests) |
| 316 | ;;; seq-tests.el ends here | 321 | ;;; seq-tests.el ends here |