emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master c49e769 1/2: Improve seq-group-by to return sequenc


From: Nicolas Petton
Subject: [Emacs-diffs] master c49e769 1/2: Improve seq-group-by to return sequence elements in correct order
Date: Wed, 11 Feb 2015 13:49:16 +0000

branch: master
commit c49e769d8f141b0307db19ed2a5fa80e0696b1dc
Author: Nicolas Petton <address@hidden>
Commit: Nicolas Petton <address@hidden>

    Improve seq-group-by to return sequence elements in correct order
    
    * lisp/emacs-lisp/seq.el (seq-group-by): Improves seq-group-by to
    return sequence elements in correct order
    * tests/automated/seq-tests.el: Update test for seq-group-by
    * doc/lispref/sequences.texi (Sequence Functions): Update documentation
    examples for seq-group-by
---
 doc/lispref/ChangeLog       |    5 +++++
 doc/lispref/sequences.texi  |    4 ++--
 lisp/ChangeLog              |    5 +++++
 lisp/emacs-lisp/seq.el      |   23 +++++++++++------------
 test/ChangeLog              |    6 ++++++
 test/automated/seq-tests.el |    6 +++---
 6 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index d82be3c..285c725 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -4,6 +4,11 @@
        fullscreen frame parameter.  Describe `fullscreen-restore'
        parameter.
 
+2015-02-09 Nicolas Petton <address@hidden>
+
+       * sequences.texi (Sequence Functions): Update documentation
+       examples for seq-group-by.
+
 2015-02-09  Eli Zaretskii  <address@hidden>
 
        * positions.texi (Screen Lines): Update the documentation of
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index f268c0d..04404f8 100644
--- a/doc/lispref/sequences.texi
+++ b/doc/lispref/sequences.texi
@@ -731,11 +731,11 @@ of @var{sequence}.  Keys are compared using @code{equal}.
 @example
 @group
 (seq-group-by #'integerp '(1 2.1 3 2 3.2))
address@hidden ((t 2 3 1) (nil 3.2 2.1))
address@hidden ((t 1 3 2) (nil 2.1 3.2))
 @end group
 @group
 (seq-group-by #'car '((a 1) (b 2) (a 3) (c 4)))
address@hidden ((a (a 3) (a 1)) (b (b 2)) (c (c 4)))
address@hidden ((b (b 2)) (a (a 1) (a 3)) (c (c 4)))
 @end group
 @end example
 @end defun
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a6e5f59..ece253b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2015-02-09  Nicolas Petton <address@hidden>
+
+       * emacs-lisp/seq.el (seq-group-by): Improves seq-group-by to
+       return sequence elements in correct order.
+
 2015-02-11  Martin Rudalics  <address@hidden>
 
        * frame.el (toggle-frame-maximized, toggle-frame-fullscreen):
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index 025d94e..5fbec18 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -4,7 +4,7 @@
 
 ;; Author: Nicolas Petton <address@hidden>
 ;; Keywords: sequences
-;; Version: 1.1
+;; Version: 1.1.1
 
 ;; Maintainer: address@hidden
 
@@ -245,17 +245,16 @@ negative integer or 0, nil is returned."
   "Apply FUNCTION to each element of SEQ.
 Separate the elements of SEQ into an alist using the results as
 keys.  Keys are compared using `equal'."
-  (nreverse
-   (seq-reduce
-    (lambda (acc elt)
-      (let* ((key (funcall function elt))
-             (cell (assoc key acc)))
-        (if cell
-            (setcdr cell (push elt (cdr cell)))
-          (push (list key elt) acc))
-        acc))
-    seq
-    nil)))
+  (seq-reduce
+   (lambda (acc elt)
+     (let* ((key (funcall function elt))
+            (cell (assoc key acc)))
+       (if cell
+           (setcdr cell (push elt (cdr cell)))
+         (push (list key elt) acc))
+       acc))
+   (seq-reverse seq)
+   nil))
 
 (defun seq--drop-list (list n)
   "Return a list from LIST without its first N elements.
diff --git a/test/ChangeLog b/test/ChangeLog
index 74fc7ce..b080961 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -3,6 +3,12 @@
        * automated/package-test.el (package-test-signed):
        More informative failure messages.
 
+2015-02-09  Nicolas Petton <address@hidden>
+
+       * automated/seq-tests.el (test-seq-group-by): Update test for
+       seq-group-by to check that sequence elements are returned in the
+       correct order.
+
 2015-02-07  Fabián Ezequiel Gallina  <address@hidden>
 
        * automated/python-tests.el (python-eldoc--get-symbol-at-point-1)
diff --git a/test/automated/seq-tests.el b/test/automated/seq-tests.el
index ecbc004..b92a15c 100644
--- a/test/automated/seq-tests.el
+++ b/test/automated/seq-tests.el
@@ -216,10 +216,10 @@ Evaluate BODY for each created sequence.
   (should (equal (seq-partition '(1 2 3) -1) '())))
 
 (ert-deftest test-seq-group-by ()
-  (should (equal (seq-group-by #'test-sequences-oddp [1 2 3 4])
-                 '((t 3 1) (nil 4 2))))
+  (should (equal (seq-group-by #'test-sequences-oddp '(1 2 3 4))
+                 '((t 1 3) (nil 2 4))))
   (should (equal (seq-group-by #'car '((a 1) (b 3) (c 4) (a 2)))
-                 '((a (a 2) (a 1)) (b (b 3)) (c (c 4))))))
+                 '((b (b 3)) (c (c 4)) (a (a 1) (a 2))))))
 
 (provide 'seq-tests)
 ;;; seq-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]