From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#57548: Add new function `seq-positions' Date: Fri, 02 Sep 2022 22:00:14 +0300 Message-ID: <83sfl9ob41.fsf@gnu.org> References: <87edwtty5v.fsf@cassou.me> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38582"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 57548@debbugs.gnu.org To: Damien Cassou Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 02 21:01:48 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oUBvH-0009tb-QY for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 02 Sep 2022 21:01:48 +0200 Original-Received: from localhost ([::1]:44158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oUBvG-0006z7-K6 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 02 Sep 2022 15:01:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUBuZ-0006xs-07 for bug-gnu-emacs@gnu.org; Fri, 02 Sep 2022 15:01:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51717) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oUBuY-0002DL-Kh for bug-gnu-emacs@gnu.org; Fri, 02 Sep 2022 15:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oUBuY-0001Kv-Fy for bug-gnu-emacs@gnu.org; Fri, 02 Sep 2022 15:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 02 Sep 2022 19:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57548 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 57548-submit@debbugs.gnu.org id=B57548.16621452495097 (code B ref 57548); Fri, 02 Sep 2022 19:01:02 +0000 Original-Received: (at 57548) by debbugs.gnu.org; 2 Sep 2022 19:00:49 +0000 Original-Received: from localhost ([127.0.0.1]:40413 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUBuK-0001K8-Mt for submit@debbugs.gnu.org; Fri, 02 Sep 2022 15:00:49 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:34890) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUBuJ-0001Jp-9B for 57548@debbugs.gnu.org; Fri, 02 Sep 2022 15:00:47 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:39700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUBuC-00029k-ET; Fri, 02 Sep 2022 15:00:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=bXnARj1qMZqjQ0elza2uP0Q2cbvgyqf4vKFXsSFkZoo=; b=KvQbJB6reF1X Pz30ihHJoVtG+6oWLqtZIw0MlLRe76HggTezqxNq+2ApQSTgSRT1QcJC2SaNTwTO5k1nh9SGRmfUy LsvoMgU6oIs6bdPDCXWsdB3JVKWBTSiuNlZwicuDEoFBRA/pV6DBj5yU3dPY2FAY4s2F372cGY/p5 Ux84eKn0oKnKDa9AfGqZ28L7GC0Cff+x57NUNlQBuZ1iKF0VLFuhfJrnuaVEAU2w1zBww42iBuTQb wmq76KOkuFEtRO11JL4mdMHTm4m7tSTxy384dip/jyx0CDvyw1GIV1oXn7HGJ7mNcFR7PcNdRez9S 4LHTzb5x0R7+sdtPMqZRkg==; Original-Received: from [87.69.77.57] (port=4463 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUBty-0003U5-F2; Fri, 02 Sep 2022 15:00:38 -0400 In-Reply-To: <87edwtty5v.fsf@cassou.me> (message from Damien Cassou on Fri, 02 Sep 2022 20:43:24 +0200) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:241354 Archived-At: > From: Damien Cassou > 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.