What about (find-if #'identity my-list)? That seems to work.
Anything better?
For an obfuscation contest, I think (find-if #'null my-list :key
#'not) would do well :) Otherwise, the function "some" is often
used here. I like to define "true" as an alias for the "identity"
function for such uses.
Also, loop is often useful:
(loop for x in my-list thereis x)
I've lately found a use for a function that calls a predicate on each
element of a list and returns all non-null results. (I bring this up
here because it has a SOME-like flavor).
(defun all-such-that (predicate list &key key)
"Return non-nil PREDICATE results for elements in LIST."
(loop for elt in list
as value = (if key
(funcall predicate (funcall key elt))
(funcall predicate elt))
when value
collect value))
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 76 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 55:43:21 |
| Calls: | 1,265 |
| Calls today: | 1 |
| Files: | 1,362 |
| D/L today: |
3 files (2,684K bytes) |
| Messages: | 285,709 |