aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/seq_utils.clj
diff options
context:
space:
mode:
authorAaron Bedra and Stuart Halloway <pair@thinkrelevance.com>2009-08-23 15:01:31 -0400
committerAaron Bedra and Stuart Halloway <pair@thinkrelevance.com>2009-08-23 15:01:31 -0400
commitb70cba0c656586836a3c951079012cd9d371fa40 (patch)
tree5978f88adabee605391e817890fe337e95c39bc7 /src/clojure/contrib/seq_utils.clj
parent0b8b47631efe950df74d17d8f410eb8196342359 (diff)
add seq-utils/positions
Diffstat (limited to 'src/clojure/contrib/seq_utils.clj')
-rw-r--r--src/clojure/contrib/seq_utils.clj18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/clojure/contrib/seq_utils.clj b/src/clojure/contrib/seq_utils.clj
index d4c29c46..5f3b7446 100644
--- a/src/clojure/contrib/seq_utils.clj
+++ b/src/clojure/contrib/seq_utils.clj
@@ -211,3 +211,21 @@
(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]
+ (for [[idx elt] (indexed coll) :when (pred elt)] idx))
+
+(defmethod positions :item [item coll]
+ (for [[idx elt] (indexed coll) :when (= item elt)] idx))
+
+
+
+