help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: return first element in list with certain property


From: Robert L.
Subject: Re: return first element in list with certain property
Date: Tue, 6 Mar 2018 00:31:14 +0000 (UTC)
User-agent: XanaNews/1.18.1.6

On 11/19/2017, Philipp Stephani wrote:

> Emanuel Berg <moasen@zoho.com> schrieb am So., 19. Nov. 2017 um 21:44 Uhr:
> 
> > What is considered the right way to return the
> > first element in list that has
> > a certain property?
> > 
> > The best way I've found so far is `cl-some' and
> > then `and'. While I don't consider the
> > "`and' hack" to be detrimental in any way I was
> > curious if there was a complete
> > "hack free" way...
> > 
> 
> cl-find-if


(defun list-find-if (pred xs)
  (while (and (consp xs) (not (funcall pred (car xs))))
    (pop xs))
  (car xs))

-- 
The report card by the American Society of Civil Engineers showed the national
infrastructure a single grade above failure, a step from declining to the point
where everyday things simply stop working the way people expect them to.
http://archive.org/details/nolies


reply via email to

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