aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Petton2015-02-09 13:14:52 +0100
committerNicolas Petton2015-02-11 14:45:51 +0100
commitc49e769d8f141b0307db19ed2a5fa80e0696b1dc (patch)
treeaa4505ccc15006aefe0649c4017e7f133ac57164
parent061c7e2b5a5a5854b2b85f2ace5b1d9222dd7f11 (diff)
downloademacs-c49e769d8f141b0307db19ed2a5fa80e0696b1dc.tar.gz
emacs-c49e769d8f141b0307db19ed2a5fa80e0696b1dc.zip
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
-rw-r--r--doc/lispref/ChangeLog5
-rw-r--r--doc/lispref/sequences.texi4
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/emacs-lisp/seq.el23
-rw-r--r--test/ChangeLog6
-rw-r--r--test/automated/seq-tests.el6
6 files changed, 32 insertions, 17 deletions
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 @@
4 fullscreen frame parameter. Describe `fullscreen-restore' 4 fullscreen frame parameter. Describe `fullscreen-restore'
5 parameter. 5 parameter.
6 6
72015-02-09 Nicolas Petton <nicolas@petton.fr>
8
9 * sequences.texi (Sequence Functions): Update documentation
10 examples for seq-group-by.
11
72015-02-09 Eli Zaretskii <eliz@gnu.org> 122015-02-09 Eli Zaretskii <eliz@gnu.org>
8 13
9 * positions.texi (Screen Lines): Update the documentation of 14 * 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}.
731@example 731@example
732@group 732@group
733(seq-group-by #'integerp '(1 2.1 3 2 3.2)) 733(seq-group-by #'integerp '(1 2.1 3 2 3.2))
734@result{} ((t 2 3 1) (nil 3.2 2.1)) 734@result{} ((t 1 3 2) (nil 2.1 3.2))
735@end group 735@end group
736@group 736@group
737(seq-group-by #'car '((a 1) (b 2) (a 3) (c 4))) 737(seq-group-by #'car '((a 1) (b 2) (a 3) (c 4)))
738@result{} ((a (a 3) (a 1)) (b (b 2)) (c (c 4))) 738@result{} ((b (b 2)) (a (a 1) (a 3)) (c (c 4)))
739@end group 739@end group
740@end example 740@end example
741@end defun 741@end defun
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a6e5f59503e..ece253b1336 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12015-02-09 Nicolas Petton <nicolas@petton.fr>
2
3 * emacs-lisp/seq.el (seq-group-by): Improves seq-group-by to
4 return sequence elements in correct order.
5
12015-02-11 Martin Rudalics <rudalics@gmx.at> 62015-02-11 Martin Rudalics <rudalics@gmx.at>
2 7
3 * frame.el (toggle-frame-maximized, toggle-frame-fullscreen): 8 * 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 @@
4 4
5;; Author: Nicolas Petton <nicolas@petton.fr> 5;; Author: Nicolas Petton <nicolas@petton.fr>
6;; Keywords: sequences 6;; Keywords: sequences
7;; Version: 1.1 7;; Version: 1.1.1
8 8
9;; Maintainer: emacs-devel@gnu.org 9;; Maintainer: emacs-devel@gnu.org
10 10
@@ -245,17 +245,16 @@ negative integer or 0, nil is returned."
245 "Apply FUNCTION to each element of SEQ. 245 "Apply FUNCTION to each element of SEQ.
246Separate the elements of SEQ into an alist using the results as 246Separate the elements of SEQ into an alist using the results as
247keys. Keys are compared using `equal'." 247keys. Keys are compared using `equal'."
248 (nreverse 248 (seq-reduce
249 (seq-reduce 249 (lambda (acc elt)
250 (lambda (acc elt) 250 (let* ((key (funcall function elt))
251 (let* ((key (funcall function elt)) 251 (cell (assoc key acc)))
252 (cell (assoc key acc))) 252 (if cell
253 (if cell 253 (setcdr cell (push elt (cdr cell)))
254 (setcdr cell (push elt (cdr cell))) 254 (push (list key elt) acc))
255 (push (list key elt) acc)) 255 acc))
256 acc)) 256 (seq-reverse seq)
257 seq 257 nil))
258 nil)))
259 258
260(defun seq--drop-list (list n) 259(defun seq--drop-list (list n)
261 "Return a list from LIST without its first N elements. 260 "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 @@
3 * automated/package-test.el (package-test-signed): 3 * automated/package-test.el (package-test-signed):
4 More informative failure messages. 4 More informative failure messages.
5 5
62015-02-09 Nicolas Petton <nicolas@petton.fr>
7
8 * automated/seq-tests.el (test-seq-group-by): Update test for
9 seq-group-by to check that sequence elements are returned in the
10 correct order.
11
62015-02-07 Fabián Ezequiel Gallina <fgallina@gnu.org> 122015-02-07 Fabián Ezequiel Gallina <fgallina@gnu.org>
7 13
8 * automated/python-tests.el (python-eldoc--get-symbol-at-point-1) 14 * 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.
216 (should (equal (seq-partition '(1 2 3) -1) '()))) 216 (should (equal (seq-partition '(1 2 3) -1) '())))
217 217
218(ert-deftest test-seq-group-by () 218(ert-deftest test-seq-group-by ()
219 (should (equal (seq-group-by #'test-sequences-oddp [1 2 3 4]) 219 (should (equal (seq-group-by #'test-sequences-oddp '(1 2 3 4))
220 '((t 3 1) (nil 4 2)))) 220 '((t 1 3) (nil 2 4))))
221 (should (equal (seq-group-by #'car '((a 1) (b 3) (c 4) (a 2))) 221 (should (equal (seq-group-by #'car '((a 1) (b 3) (c 4) (a 2)))
222 '((a (a 2) (a 1)) (b (b 3)) (c (c 4)))))) 222 '((b (b 3)) (c (c 4)) (a (a 1) (a 2))))))
223 223
224(provide 'seq-tests) 224(provide 'seq-tests)
225;;; seq-tests.el ends here 225;;; seq-tests.el ends here