]> code.delx.au - gnu-emacs/commitdiff
Improve seq-group-by to return sequence elements in correct order
authorNicolas Petton <nicolas@petton.fr>
Mon, 9 Feb 2015 12:14:52 +0000 (13:14 +0100)
committerNicolas Petton <nicolas@petton.fr>
Wed, 11 Feb 2015 13:45:51 +0000 (14:45 +0100)
* 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
doc/lispref/sequences.texi
lisp/ChangeLog
lisp/emacs-lisp/seq.el
test/ChangeLog
test/automated/seq-tests.el

index d82be3c83e77b3a7eff493cef36bcb77a6c7b08e..285c725caeffcd36c072297359fc339922885bf4 100644 (file)
@@ -4,6 +4,11 @@
        fullscreen frame parameter.  Describe `fullscreen-restore'
        parameter.
 
+2015-02-09 Nicolas Petton <nicolas@petton.fr>
+
+       * sequences.texi (Sequence Functions): Update documentation
+       examples for seq-group-by.
+
 2015-02-09  Eli Zaretskii  <eliz@gnu.org>
 
        * positions.texi (Screen Lines): Update the documentation of
index f268c0d11e238cfe6576f7f5e3d33d33c9305b45..04404f886e0310b25fee3519a585bfaf87fabcef 100644 (file)
@@ -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))
-@result{} ((t 2 3 1) (nil 3.2 2.1))
+@result{} ((t 1 3 2) (nil 2.1 3.2))
 @end group
 @group
 (seq-group-by #'car '((a 1) (b 2) (a 3) (c 4)))
-@result{} ((a (a 3) (a 1)) (b (b 2)) (c (c 4)))
+@result{} ((b (b 2)) (a (a 1) (a 3)) (c (c 4)))
 @end group
 @end example
 @end defun
index a6e5f59503e6f30faf74719b4fd7d78c40f253a7..ece253b1336142d23fde1854cddb129ca55a77f7 100644 (file)
@@ -1,3 +1,8 @@
+2015-02-09  Nicolas Petton <nicolas@petton.fr>
+
+       * emacs-lisp/seq.el (seq-group-by): Improves seq-group-by to
+       return sequence elements in correct order.
+
 2015-02-11  Martin Rudalics  <rudalics@gmx.at>
 
        * frame.el (toggle-frame-maximized, toggle-frame-fullscreen):
index 025d94e10b9a1d9762b47edc68c6d3410125c2d7..5fbec185b761a4f56325d05cefac7b263fc2ddbc 100644 (file)
@@ -4,7 +4,7 @@
 
 ;; Author: Nicolas Petton <nicolas@petton.fr>
 ;; Keywords: sequences
-;; Version: 1.1
+;; Version: 1.1.1
 
 ;; Maintainer: emacs-devel@gnu.org
 
@@ -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.
index 74fc7cebd563ba445aca18eeb5ac2455f2794e0b..b080961f681c8ee2a764ef36ae2939a6f3a039cb 100644 (file)
@@ -3,6 +3,12 @@
        * automated/package-test.el (package-test-signed):
        More informative failure messages.
 
+2015-02-09  Nicolas Petton <nicolas@petton.fr>
+
+       * 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  <fgallina@gnu.org>
 
        * automated/python-tests.el (python-eldoc--get-symbol-at-point-1)
index ecbc004321010414d21845e95ec3bdee88567411..b92a15cacc5ff2210649289bb8d3eb4b4eee9334 100644 (file)
@@ -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