Skip to content

clojure.core/any?

View this page on ClojureDocs

Type: function Added: Clojure 1.9 Examples: 3 Runnable: 2
([x])

Returns true given any argument.

Examples

by phreed on . May have evaluation errors.
by berczeck on
by tomdl89 on

Note by kofrasa

The current implementation of any? is incorrect and must be fixed IMO. There was a PR (copied below) submitted in 2014 to add a correct implementation which is consistent with behaviour in other languages.

(def
 ^{:tag Boolean
   :doc "Returns true if (pred x) is logical true for any x in coll,
  else false."
   :arglists '([pred coll])
   :added "1.7"}
 any? (comp boolean some))

Note by berczeck

any? never returns false. Is this a bug?

Note by KyleErhabor

You can think of this function as a non-variadic (constantly true).

Note by wildwestrom

Explanation by Alex Miller:

any? is a predicate that is intended to always return true, so yes it is the correct behavior. any? was added as a predicate to use with spec in the case where any value is valid. It is not a complement to not-any?, despite that obvious assumption. There are, in the end, only so many words and despite a lot of care in this regard, there are times when these confusions exist.

...this is similar to and (for N args) but that does have limits as a macro, or every? (for a coll), or the higher-order function every-pred for creating a composite pred. Depending on your case, one of those probably makes sense.

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.