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: Emanuel Berg
Subject: Re: return first element in list with certain property
Date: Mon, 20 Nov 2017 22:16:49 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Eric Abrahamsen wrote:

> FWIW, this is essentially how seq-find works,
> and I generally use this.

Here (my use case) it is important that the
search is linear along the list from the
beginning as the hit is almost always in the
very early section of the list.

However the below tests seem to indicate no
problems for any of the solutions suggested
so far?

(let ((test-list '(0 1 2 3 4 5)))

  (cl-dolist (e test-list)
    (message "cl-dolist processing: %s" e)
    (when (> e 1) (cl-return e) ))

  (cl-find-if (lambda (e) (and (message "cl-find-if processing: %s" e)
                               (> e 1) ))
              test-list)

  (seq-find   (lambda (e) (and (message "find-seq processing: %s" e)
                               (> e 1) ))
              test-list)
  )
;; cl-dolist processing: 0
;; cl-dolist processing: 1
;; cl-dolist processing: 2
;; cl-find-if processing: 0
;; cl-find-if processing: 1
;; cl-find-if processing: 2
;; find-seq processing: 0
;; find-seq processing: 1
;; find-seq processing: 2

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

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