Skip to content

Commit 9fcd8ae

Browse files
committed
improve doc for contains? and some, patch from Chouser
1 parent da42d50 commit 9fcd8ae

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/clj/clojure/core.clj

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,12 @@
873873
;;map stuff
874874

875875
(defn contains?
876-
"Returns true if key is present, else false."
877-
[map key] (. clojure.lang.RT (contains map key)))
876+
"Returns true if key is present in the given collection, otherwise
877+
returns false. Note that for numerically indexed collections like
878+
vectors and Java arrays, this tests if the numeric key is within the
879+
range of indexes. 'contains?' operates constant or logarithmic time;
880+
it will not perform a linear search for a value. See also 'some'."
881+
[coll key] (. clojure.lang.RT (contains coll key)))
878882

879883
(defn get
880884
"Returns the value mapped to key, not-found or nil if key not present."
@@ -1349,7 +1353,9 @@
13491353

13501354
(defn some
13511355
"Returns the first logical true value of (pred x) for any x in coll,
1352-
else nil."
1356+
else nil. One common idiom is to use a set as pred, for example
1357+
this will return true if :fred is in the sequence, otherwise nil:
1358+
(some #{:fred} coll)"
13531359
[pred coll]
13541360
(when (seq coll)
13551361
(or (pred (first coll)) (recur pred (rest coll)))))

0 commit comments

Comments
 (0)