[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is there already an alist function which gets all matching elements,
From: |
Alan Mackenzie |
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 |
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).