emacs-devel
[Top][All Lists]
Advanced

[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: Philip Kaludercic
Subject: Re: Is there already an alist function which gets all matching elements, not just the first?
Date: Wed, 05 Oct 2022 18:16:43 +0000

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))

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.

> Thanks!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]