From 05211a578ed2c52f6ed818fc173561afbaea54c2 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Fri, 6 Feb 2015 15:52:23 +0100 Subject: [PATCH] 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 32bbd2ccf3f..aa58c5349aa 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2015-02-06 Nicolas Petton + + * emacs-lisp/seq.el (seq-mapcat): New function. + 2015-02-06 Artur Malabarba * 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 +;; Author: Nicolas Petton ;; 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 + + * automated/seq-tests.el: New test for seq-mapcat. + 2015-02-05 Artur Malabarba * 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 +;; Author: Nicolas Petton ;; 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 -- 2.39.5