GNU bug report logs -
#57548
Add new function `seq-positions'
Previous Next
Reported by: Damien Cassou <damien <at> cassou.me>
Date: Fri, 2 Sep 2022 18:50:02 UTC
Severity: normal
Tags: patch
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #8 received at 57548 <at> debbugs.gnu.org (full text, mbox):
> From: Damien Cassou <damien <at> cassou.me>
> Date: Fri, 02 Sep 2022 20:43:24 +0200
>
> +@defun seq-positions sequence elt &optional testfn
> + This function returns a list of the positions of the elements in
> +@var{sequence} that are equal to @var{elt}.
We use "index", not "position". In any case, the documentation should
explain what you mean by that, and it should definitely say that the
index/position are zero-based.
> +@example
> +@group
> +(seq-positions '(a b c a d) 'a)
> +@result{} (0 3)
> +@end group
> +@group
> +(seq-position '(a b c a d) 'z)
> +@result{} nil
seq-position or seq-positions?
> +(cl-defgeneric seq-positions (sequence elt &optional testfn)
> + "Return a list of the positions of ELT in SEQ.
> +Equality is defined by TESTFN if non-nil or by `equal' if nil."
Our style is to say
Equality is defined by the function TESTFN, which defaults to `equal'.
> --- a/test/lisp/emacs-lisp/seq-tests.el
> +++ b/test/lisp/emacs-lisp/seq-tests.el
> @@ -482,6 +482,11 @@ test-seq-position
> (should (= (seq-position seq 'a #'eq) 0))
> (should (null (seq-position seq (make-symbol "a") #'eq)))))
>
> +(ert-deftest test-seq-positions ()
> + (with-test-sequences (seq '(1 2 3 1 4))
> + (should (equal '(0 3) (seq-positions seq 1)))
> + (should (seq-empty-p (seq-positions seq 9)))))
Should we test more than just one type of sequences?
Thanks.
This bug report was last modified 2 years and 317 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.