From: Nicolas Petton Date: Mon, 9 Feb 2015 12:14:52 +0000 (+0100) Subject: Improve seq-group-by to return sequence elements in correct order X-Git-Tag: emacs-25.0.90~2564^2~400 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c49e769d8f141b0307db19ed2a5fa80e0696b1dc;p=emacs.git 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 --- diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index d82be3c83e7..285c725caef 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 + + * sequences.texi (Sequence Functions): Update documentation + examples for seq-group-by. + 2015-02-09 Eli Zaretskii * positions.texi (Screen Lines): Update the documentation of diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index f268c0d11e2..04404f886e0 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)) -@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 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a6e5f59503e..ece253b1336 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2015-02-09 Nicolas Petton + + * emacs-lisp/seq.el (seq-group-by): Improves seq-group-by to + return sequence elements in correct order. + 2015-02-11 Martin Rudalics * frame.el (toggle-frame-maximized, toggle-frame-fullscreen): diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el index 025d94e10b9..5fbec185b76 100644 --- a/lisp/emacs-lisp/seq.el +++ b/lisp/emacs-lisp/seq.el @@ -4,7 +4,7 @@ ;; Author: Nicolas Petton ;; 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. diff --git a/test/ChangeLog b/test/ChangeLog index 74fc7cebd56..b080961f681 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 + + * 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 * 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 ecbc0043210..b92a15cacc5 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