From: Alan Mackenzie <acm@muc.de>
To: Philip Kaludercic <philipk@posteo.net>
Cc: emacs-devel@gnu.org
Subject: Re: Is there already an alist function which gets all matching elements, not just the first?
Date: Thu, 6 Oct 2022 18:34:58 +0000 [thread overview]
Message-ID: <Yz8f0rokIt+nUKMm@ACM> (raw)
In-Reply-To: <87y1tum8z8.fsf@posteo.net>
Hello, Philip.
On Wed, Oct 05, 2022 at 18:16:43 +0000, Philip Kaludercic wrote:
> Alan Mackenzie <acm@muc.de> writes:
> > Hello, Emacs.
> > I want to be able to get all matching elements from an alist (thinking
> > about extending imenu). Something like
> > (assoc-all key list)
> > which would return a list of matches. After all, we have functions
> > which _delete_ all matches from an alist.
> > Does such a function already exist, perhaps in cl-*.el?
> This appears to do the right thing
> (map-filter (lambda (k _v) (eq k '3))
> '((3 . 4)
> (2 . 4)
> (1 . 2)
> (3 . 1)))
> ;; => ((3 . 4) (3 . 1))
The doc string for map-filter doesn't actually describe the function,
sadly. It talks about key/value pairs whilst giving no clue where the
key and the value come from. I suppose one might guess, but really
there's no alternative to studying the source code for map-filter.
> Perhaps a `map-member' could be implemented that would do something like
> what you are looking for? Or does this already exist by some other name
> (I don't really use map.el). I've certainly wanted something like this
> more than a few times.
It seems like one of these things which quite a lot of people want, but
nobody wants it enough to be bothered to implement it. ;-)
> > Thanks!
--
Alan Mackenzie (Nuremberg, Germany).
prev parent reply other threads:[~2022-10-06 18:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-05 10:00 Is there already an alist function which gets all matching elements, not just the first? Alan Mackenzie
2022-10-05 10:45 ` Robert Pluim
2022-10-06 18:24 ` Alan Mackenzie
2022-10-05 18:16 ` Philip Kaludercic
2022-10-05 18:35 ` Lars Ingebrigtsen
2022-10-06 18:34 ` Alan Mackenzie [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yz8f0rokIt+nUKMm@ACM \
--to=acm@muc.de \
--cc=emacs-devel@gnu.org \
--cc=philipk@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.