Skip to content
Browse files

put includes? back into the seq namespaces

  - seq-contains? is dead in clojure
  - includes? is deprecated, but no need to gratuitously break people
  • Loading branch information...
1 parent eb7021a commit 48b81e07256c697c23a1aff896596300e7d0115b @stuarthalloway stuarthalloway committed May 3, 2010
View
8 src/main/clojure/clojure/contrib/seq.clj
@@ -140,7 +140,13 @@
[pred coll]
(for [[idx elt] (indexed coll) :when (pred elt)] idx))
-
+(defn includes?
+ "Returns true if coll contains something equal (with =) to x,
+ in linear time. Deprecated. prefer 'contains?' for key testing,
+ or 'some' for ad hoc linear searches."
+ {:deprecated true}
+ [coll x]
+ (boolean (some (fn [y] (= y x)) coll)))
View
7 src/main/clojure/clojure/contrib/seq_utils.clj
@@ -141,6 +141,13 @@
[pred coll]
(for [[idx elt] (indexed coll) :when (pred elt)] idx))
+(defn includes?
+ "Returns true if coll contains something equal (with =) to x,
+ in linear time. Deprecated. Prefer 'contains?' for key testing,
+ or 'some' for ad hoc linear searches."
+ {:deprecated true}
+ [coll x]
+ (boolean (some (fn [y] (= y x)) coll)))
View
9 src/test/clojure/clojure/contrib/test_seq.clj
@@ -72,3 +72,12 @@
(deftest test-find-first
(is (= (find-first even? [1 2 3 4 5]) 2))
(is (= (find-first even? '(1 2 3 4 5)) 2)))
+
+(deftest test-includes
+ (are [coll k] (false? (includes? coll k))
+ [1 2 3] 0
+ [] nil
+ [:a :b] :c)
+ (are [coll k] (true? (includes? coll k))
+ [1 2 3] 1
+ [:a :b] :b))

0 comments on commit 48b81e0

Please sign in to comment.
Something went wrong with that request. Please try again.