aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/expect/util.clj
diff options
context:
space:
mode:
authorAaron Bedra and Stuart Halloway <pair@thinkrelevance.com>2009-08-23 13:09:53 -0400
committerAaron Bedra and Stuart Halloway <pair@thinkrelevance.com>2009-08-23 13:09:53 -0400
commitcf4790b017ab4d2840f9d224abfa9c6023f71262 (patch)
tree83858019c5136c5d50959f99808942701fb89dbd /src/clojure/contrib/expect/util.clj
parent6b763062af9568c1b069d5f86c8d5481a3fdfeea (diff)
added test-expect source, renamed namespaces for contrib
Diffstat (limited to 'src/clojure/contrib/expect/util.clj')
-rw-r--r--src/clojure/contrib/expect/util.clj21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/clojure/contrib/expect/util.clj b/src/clojure/contrib/expect/util.clj
new file mode 100644
index 00000000..a5b018c1
--- /dev/null
+++ b/src/clojure/contrib/expect/util.clj
@@ -0,0 +1,21 @@
+(ns clojure.contrib.expect.util
+ (:use clojure.contrib.seq-utils))
+
+(defmacro assert-args [fnname & pairs]
+ `(do (when-not ~(first pairs)
+ (throw (IllegalArgumentException.
+ ~(str fnname " requires " (second pairs)))))
+ ~(let [more (nnext pairs)]
+ (when more
+ (list* `assert-args fnname more)))))
+
+(defn indexes
+ "Returns a lazy sequence of the indexes in coll for which the element
+is equal to v."
+ [coll v]
+ (map #(first %) (filter (fn [[i el]] (= el v)) (indexed coll))))
+
+(defn index-of
+ "Returns the first index of value v in the collection or nil."
+ [coll v]
+ (first (indexes coll v)))