[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#57548: Add new function `seq-positions'
From: |
Eli Zaretskii |
Subject: |
bug#57548: Add new function `seq-positions' |
Date: |
Fri, 02 Sep 2022 22:00:14 +0300 |
> From: Damien Cassou <damien@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.
- bug#57548: Add new function `seq-positions', Damien Cassou, 2022/09/02
- bug#57548: Add new function `seq-positions',
Eli Zaretskii <=
- bug#57548: Add new function `seq-positions', Damien Cassou, 2022/09/03
- bug#57548: Add new function `seq-positions', Michael Heerdegen, 2022/09/03
- bug#57548: Add new function `seq-positions', Damien Cassou, 2022/09/04
- bug#57548: Add new function `seq-positions', Lars Ingebrigtsen, 2022/09/04
- bug#57548: Add new function `seq-positions', Michael Heerdegen, 2022/09/05
bug#57548: Add new function `seq-positions', Michael Heerdegen, 2022/09/02