0

i know that member returns non-nil if the element is found in the list, but it only returns the tail of the list from element onwards. is there a way to return the full list it is a member of?

my case: i'm iterating over a list of plists, and i want to return the particular plist that contains what i search for (i want to access/use the other info the plist contains).

my solution so far looks like this:

 (cl-dolist (child-list parent-list)
   (when (string= (plist-get child-list 'property)
                  "value")
     (cl-return child-list)))

is there a more idiomatic way to go about this? the query is not so much member? or -contains?, as which-list-contains?

4
  • 1
    Check out seq-find (or seq-filter if you would like to 'filter' out multiple matching lists) Mar 24, 2022 at 17:39
  • @dalanicolai thx for drawing those to my attention. but maybe i'm still missing something: how to construct a predicate that can pass each plist to plist-get as an argument (i.e. child-list in my example).
    – martian
    Mar 24, 2022 at 17:50
  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Mar 24, 2022 at 18:49
  • is there a way to return the full list it is a member of? The full list is the list you passed to member, no? Not too clear to me what you're asking.
    – Drew
    Mar 24, 2022 at 18:57

1 Answer 1

1

As @dalanicolai suggested:

(seq-find 
  (lambda (plist) 
    (plist-get plist :property)) 
  '((:foo bar) (:baz frob :property quux)))

;; => (:baz frob :property quux)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.