I have the following function defined in my .emacs
to test if a given executable exists within my $PATH
. I implemented it with cl-reduce
and the code looks really unidiomatic (to me).
(defun executable-in-path-p (executable)
"Test if EXECUTABLE exists in path."
(eq t (cl-reduce
(lambda (path exists)
(or (file-exists-p (concat (file-name-as-directory path) executable))
exists))
exec-path)))
Is there a more concise way to test if a list, mapped with a predicate function, has at least one element equal to t
than this?
(eq t
(cl-reduce
(lambda (element acc)
(or (some-check-p element)
acc))
some-list))
In Ruby for example I would write:
some_list.any? { |element| some_check(element) }