[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 05211a5 1/4: Add seq-mapcat
From: |
Nicolas Petton |
Subject: |
[Emacs-diffs] master 05211a5 1/4: Add seq-mapcat |
Date: |
Fri, 06 Feb 2015 15:02:19 +0000 |
branch: master
commit 05211a578ed2c52f6ed818fc173561afbaea54c2
Author: Nicolas Petton <address@hidden>
Commit: Nicolas Petton <address@hidden>
Add seq-mapcat
* lisp/emacs-lisp/seq.el (seq-mapcat): New function
* test/automated/seq-tests.el: Add unit tests for seq-mapcat
---
lisp/ChangeLog | 4 ++++
lisp/emacs-lisp/seq.el | 10 ++++++++--
test/ChangeLog | 4 ++++
test/automated/seq-tests.el | 10 +++++++++-
4 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 32bbd2c..aa58c53 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
+2015-02-06 Nicolas Petton <address@hidden>
+
+ * emacs-lisp/seq.el (seq-mapcat): New function.
+
2015-02-06 Artur Malabarba <address@hidden>
* 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 b28153b..bd234a3 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 <address@hidden>
+;; Author: Nicolas Petton <address@hidden>
;; Keywords: sequences
-;; Version: 1.0
+;; Version: 1.1
;; Maintainer: address@hidden
@@ -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 23c4870..9ae9db3 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
+2015-02-02 Nicolas Petton <address@hidden>
+
+ * automated/seq-tests.el: New test for seq-mapcat.
+
2015-02-05 Artur Malabarba <address@hidden>
* 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 2398979..cc89c88 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 <address@hidden>
+;; Author: Nicolas Petton <address@hidden>
;; Maintainer: address@hidden
;; 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