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
This commit is contained in:
parent
061c7e2b5a
commit
c49e769d8f
6 changed files with 32 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue