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: Marco Wahl
Subject: Re: return first element in list with certain property
Date: Sun, 19 Nov 2017 22:20:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Emanuel Berg <moasen@zoho.com> writes:

> 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...
>
> Example: get the first element that is bigger
> than 1:
>
>     (cl-some (lambda (e) (and (> e 1) e)) '(1 1 3 1 4 2)) ; 3

(cl-loop for e in '(1 1 3 1 4 2)
         when (> e 1)
         return e)

lgtm


reply via email to

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