summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Petton <nicolas@petton.fr>2015-02-06 15:52:23 +0100
committerNicolas Petton <nicolas@petton.fr>2015-02-06 15:52:23 +0100
commit05211a578ed2c52f6ed818fc173561afbaea54c2 (patch)
tree6070ecbed3f1c61b5d48886f06848308f8302ece
parent5c9ad35f1e5fd8ee5561ef48baac1f6ff20ae679 (diff)
downloademacs-05211a578ed2c52f6ed818fc173561afbaea54c2.tar.gz
Add seq-mapcat
* lisp/emacs-lisp/seq.el (seq-mapcat): New function * test/automated/seq-tests.el: Add unit tests for seq-mapcat
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/emacs-lisp/seq.el10
-rw-r--r--test/ChangeLog4
-rw-r--r--test/automated/seq-tests.el10
4 files changed, 25 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 32bbd2ccf3f..aa58c5349aa 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
+2015-02-06 Nicolas Petton <nicolas@petton.fr>
+
+ * emacs-lisp/seq.el (seq-mapcat): New function.
+
2015-02-06 Artur Malabarba <bruce.connor.am@gmail.com>
* doc-view.el (doc-view-kill-proc-and-buffer): Obsolete. Use
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index b28153b7f81..bd234a3b55a 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -2,9 +2,9 @@
;; Copyright (C) 2014-2015 Free Software Foundation, Inc.
-;; Author: Nicolas Petton <petton.nicolas@gmail.com>
+;; Author: Nicolas Petton <nicolas@petton.fr>
;; Keywords: sequences
-;; Version: 1.0
+;; Version: 1.1
;; Maintainer: emacs-devel@gnu.org
@@ -224,6 +224,12 @@ TYPE must be one of following symbols: vector, string or list.
(`list (apply #'append (append seqs '(nil))))
(t (error "Not a sequence type name: %s" type))))
+(defun seq-mapcat (function seq &optional type)
+ "Concatenate the result of applying FUNCTION to each element of SEQ.
+The result is a sequence of type TYPE, or a list if TYPE is nil."
+ (apply #'seq-concatenate (or type 'list)
+ (seq-map function seq)))
+
(defun seq--drop-list (list n)
"Optimized version of `seq-drop' for lists."
(while (and list (> n 0))
diff --git a/test/ChangeLog b/test/ChangeLog
index 23c48708b6c..9ae9db3f8fb 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
+2015-02-02 Nicolas Petton <nicolas@petton.fr>
+
+ * automated/seq-tests.el: New test for seq-mapcat.
+
2015-02-05 Artur Malabarba <bruce.connor.am@gmail.com>
* automated/package-test.el (package-test-get-deps): Fix typo.
diff --git a/test/automated/seq-tests.el b/test/automated/seq-tests.el
index 23989799306..cc89c889675 100644
--- a/test/automated/seq-tests.el
+++ b/test/automated/seq-tests.el
@@ -2,7 +2,7 @@
;; Copyright (C) 2014-2015 Free Software Foundation, Inc.
-;; Author: Nicolas Petton <petton.nicolas@gmail.com>
+;; Author: Nicolas Petton <nicolas@petton.fr>
;; Maintainer: emacs-devel@gnu.org
;; This file is part of GNU Emacs.
@@ -197,5 +197,13 @@ Evaluate BODY for each created sequence.
(should (equal (seq-concatenate 'vector nil '(8 10)) [8 10]))
(should (equal (seq-concatenate 'vector seq nil) [2 4 6]))))
+(ert-deftest test-seq-mapcat ()
+ (should (equal (seq-mapcat #'seq-reverse '((3 2 1) (6 5 4)))
+ '(1 2 3 4 5 6)))
+ (should (equal (seq-mapcat #'seq-reverse '[(3 2 1) (6 5 4)])
+ '(1 2 3 4 5 6)))
+ (should (equal (seq-mapcat #'seq-reverse '((3 2 1) (6 5 4)) 'vector)
+ '[1 2 3 4 5 6])))
+
(provide 'seq-tests)
;;; seq-tests.el ends here