contains?

functionsince v0.0-927 clojure.core/contains?Edit
(contains? coll v)

Details:

Returns true if the coll contains the lookup key v, otherwise returns false.

Note that for numerically indexed collections like vectors and arrays, this tests if the numeric key is within the range of indexes.

contains? operates in constant or logarithmic time, using get to perform the lookup. It will not perform a linear search for a value. some is used for this purpose:

(some #{value} coll)

Examples:

Sets and Maps provide key lookups, so contains? works as expected:

(contains? #{:a :b} :a)
;;=> true

(contains? {:a 1, :b 2} :a)
;;=> true

(contains? {:a 1, :b 2} 1)
;;=> false

Vectors provide integer index lookups, so contains? works appropriately:

(contains? [:a :b] :b)
;;=> false

(contains? [:a :b] 1)
;;=> true

Lists and Sequences do not provide lookups, so contains? will not work:

(contains? '(:a :b) :a)
;;=> false

(contains? '(:a :b) 1)
;;=> false

(contains? (range 3) 1)
;;=> false

See Also:


Source docstring:
Returns true if key is present in the given collection, otherwise
returns false.  Note that for numerically indexed collections like
vectors and arrays, this tests if the numeric key is within the
range of indexes. 'contains?' operates constant or logarithmic time;
it will not perform a linear search for a value.  See also 'some'.
Source code @ clojurescript:src/main/cljs/cljs/core.cljs
(defn ^boolean contains?
  [coll v]
  (if (identical? (get coll v lookup-sentinel) lookup-sentinel)
    false
    true))