|
From: | Drew Adams |
Subject: | RE: [External] : Re: Testing whether a list contains at least one non-nil element |
Date: | Tue, 25 Oct 2022 15:59:59 +0000 |
> > I would like to test whether a list contains > > at least one non-nil element? > > I'd use `cl-some': (cl-some #'identity my-list). > There are lots of other possible solutions, like > using a simple `while' loop or a `dolist' with > `catch' and `throw'. IOW: (setq toto '(nil nil 3 nil nil)) (defun foo (xs) (while (and (not (car xs)) xs) (setq xs (cdr xs))) (car xs)) (defun bar (xs) (catch 'bar (dolist (x xs) (when x (throw 'bar t))) nil)) (foo toto) (bar toto) Or just: (cl-member-if-not #'null toto)
[Prev in Thread] | Current Thread | [Next in Thread] |