From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.bugs Subject: bug#57548: Add new function `seq-positions' Date: Sat, 03 Sep 2022 03:42:02 +0200 Message-ID: <877d2l5j4l.fsf@web.de> References: <87edwtty5v.fsf@cassou.me> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13915"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) 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 Sat Sep 03 03:43:14 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 1oUIBl-0003Qh-Eg for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 03 Sep 2022 03:43:13 +0200 Original-Received: from localhost ([::1]:44296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oUIBk-0004LE-0C for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 02 Sep 2022 21:43:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oUIBa-0004Kh-V4 for bug-gnu-emacs@gnu.org; Fri, 02 Sep 2022 21:43:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51932) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oUIBa-0008Cu-LT for bug-gnu-emacs@gnu.org; Fri, 02 Sep 2022 21:43:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oUIBa-0005C1-CL for bug-gnu-emacs@gnu.org; Fri, 02 Sep 2022 21:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Heerdegen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 03 Sep 2022 01:43: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.166216933419903 (code B ref 57548); Sat, 03 Sep 2022 01:43:02 +0000 Original-Received: (at 57548) by debbugs.gnu.org; 3 Sep 2022 01:42:14 +0000 Original-Received: from localhost ([127.0.0.1]:40631 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUIAo-0005Aw-CT for submit@debbugs.gnu.org; Fri, 02 Sep 2022 21:42:14 -0400 Original-Received: from mout.web.de ([212.227.15.4]:52779) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oUIAm-0005Aj-EM for 57548@debbugs.gnu.org; Fri, 02 Sep 2022 21:42:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1662169326; bh=180ZiBJUVHhSxMOs/g5fchal/r59cGYlOTcgkDzqwgM=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=X8pI1GnIHwJBFgipz4z7mpCotM8bCFN6ZP/rGu+FjuBBssBac3yEX6DZAne2DeLBp JquAeHGugoF0aRQz0uaLHfirhCDSIugw0Y008aZv5rerqpd4k72m0zYSTGcJoO02By eAeCZmWdnYE4pb92/Y4UJeu0mtdCbZlcbXmR22Ds= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Original-Received: from drachen.dragon ([84.57.248.18]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MY5bV-1ottcu3OPd-00YZTM; Sat, 03 Sep 2022 03:42:05 +0200 In-Reply-To: <87edwtty5v.fsf@cassou.me> (Damien Cassou's message of "Fri, 02 Sep 2022 20:43:24 +0200") X-Provags-ID: V03:K1:aN4QXmUWkpzL12sH+pmK+Q9hdtBvZoOnkbsdSD6q7arXL+TNwEn UCGLz1Q2vPEldOutCpGedtMeVb87nfvhnw+NLRiKLLYzHux8L+LPL7xHTURsRtJAhruN1U7 omPbVOcTcd2XYMnS+hyQMd3fg0YGLuucajQWOyGtCckBzZRQS4JelH5AD6iWsAXRq1e/HxT 98Nq4J5AYAgSZOFjK0blA== X-UI-Out-Filterresults: notjunk:1;V03:K0:5ThP1N+h92k=:1DBFTOqFnMQXqxEpGwtGml 0tWnR4PLWZrHil5vNdTiWfj73axZ7rfTMxWhE0k5TSzO/2dSYy9uRrDQ3h1qHVepAC+V1U9dW zpfHgP7Rx21LzrmJX/CcOm1USc0bgdcdNLGP9FGonl5WP0na0iHBX7ccEFsmF7AOTRL+/BIOy HP2kvI7LZUT7ppCdsZLqjgX2h36ST2l3r1wCkNFhWjPkMfPcK0MyiK3L086akXa5k/unABo1j NQ9NxxPQWrifRFsQ7I0beYsaF3Io0u8/G9C3w3sEefm0eVS4ryYG0JGbLDIYJNxCAAGCw99cZ K3sP61e3uzfA2LyW/mDrV69aNEYEqnbCMgqGBmA2R7AD62Y+3ztjboNdx9QTgHBdlxabta9f+ bBQldJR4eYqH0UMfw1g7ciIwjzW7zzFJ6U0nQSGeyGhVLA2k8FDN0kvpPkaOd4hCdATnLmVdc Unx+5PuZ0qIXbMKyJkIpJDqZJNeI/VrRToMlao1RUwzvMa6uRXPu0LAQw6IxLitmilcNSynYt lP2ll4cC9eGAwaQZo+tu4lwnQVXp5Dt0gihcRTk2g5JMN0RcdHwYlwzsI9HySb8hNCdxdOTrJ e0nvYNYwYD0QSVv7/WQMwitD2w5WhjqvrQidhwJXJXpzk1N6lWhDeq9WQ5OIRXiH/eToJ/INS cwvWQExOzKVEZ/CRDQ9VJzj8pRIxDyAhJz8XQ/4yo2OGPrsSFy8BFhCFt/PZMcBAH1+KvBzZx 0DgjukZxSncFd84QAePcgK4mjrgSqp0w6xGYgG7ayBPG1XudQ5E599CwJQ1//SUtmDCgNKOp 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:241362 Archived-At: Damien Cassou writes: > here is a patch adding seq-positions to seq.el. +@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}. If the optional argument +@var{testfn} is non-@code{nil}, it is a function of two arguments to +use instead of the default @code{equal}. We do not need to limit this to equivalence relations. A TESTFUN of, say, (apply-partially #'<= 10) could be similarly useful. +;;;###autoload +(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." + (let ((result '()) + (index 0)) + (seq-doseq (e sequence) + (when (funcall (or testfn #'equal) e elt) + (push index result)) + (setq index (1+ index))) + (nreverse result))) Could this maybe (simpler) call `seq-do-indexed'? TIA, Michael.