aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Bedra and Stuart Halloway <pair@thinkrelevance.com>2009-08-25 21:11:59 -0400
committerAaron Bedra and Stuart Halloway <pair@thinkrelevance.com>2009-08-25 21:11:59 -0400
commit1640c0433e35cf9a60e1483424c0a2a8ca56b730 (patch)
tree9ca74826e518cef7cccbdfe509c93babc4b69867
parent3a220e3af24bd5bd30869a112c7210a888ea6dc4 (diff)
positions takes only a predicate, per Rich's feedback
-rw-r--r--src/clojure/contrib/expect/util.clj2
-rw-r--r--src/clojure/contrib/seq_utils.clj16
-rw-r--r--src/clojure/contrib/test_contrib/seq_utils_test.clj5
3 files changed, 6 insertions, 17 deletions
diff --git a/src/clojure/contrib/expect/util.clj b/src/clojure/contrib/expect/util.clj
index 14bd6d16..6b834570 100644
--- a/src/clojure/contrib/expect/util.clj
+++ b/src/clojure/contrib/expect/util.clj
@@ -12,4 +12,4 @@
(defn index-of
"Returns the first index of value v in the collection or nil."
[coll v]
- (first (positions v coll)))
+ (first (positions #{v} coll)))
diff --git a/src/clojure/contrib/seq_utils.clj b/src/clojure/contrib/seq_utils.clj
index 5f3b7446..ad913f70 100644
--- a/src/clojure/contrib/seq_utils.clj
+++ b/src/clojure/contrib/seq_utils.clj
@@ -211,20 +211,12 @@
(cons (if (identical? x NIL) nil x)
(drain))))))))))
-(defmulti positions
- "Returns a lazy sequence containing the positions at which item
- is found in coll. Functions (responding true to fn?) are called
- against members of the collection, other items are compared for
- equality."
- { :arglists '([item-or-pred coll]) }
- (fn [item-or-pred _]
- (if (fn? item-or-pred) :pred :item)))
-
-(defmethod positions :pred [pred coll]
+(defn positions
+ "Returns a lazy sequence containing the positions at which pred
+ is true for items in coll."
+ [pred coll]
(for [[idx elt] (indexed coll) :when (pred elt)] idx))
-(defmethod positions :item [item coll]
- (for [[idx elt] (indexed coll) :when (= item elt)] idx))
diff --git a/src/clojure/contrib/test_contrib/seq_utils_test.clj b/src/clojure/contrib/test_contrib/seq_utils_test.clj
index 1de61cb5..f8815041 100644
--- a/src/clojure/contrib/test_contrib/seq_utils_test.clj
+++ b/src/clojure/contrib/test_contrib/seq_utils_test.clj
@@ -5,10 +5,7 @@
(deftest test-positions
(are [expected pred coll] (= expected (positions pred coll))
- [1] nil [0 nil 5]
- [1] nil? [0 nil 5]
- () string? [:a :b :c]
[2] string? [:a :b "c"]
() :d [:a :b :c]
- [0 2] :d [:d :a :d :a]))
+ [0 2] #{:d} [:d :a :d :a]))
\ No newline at end of file