aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib/expect/util.clj
blob: a5b018c1172a042dd3b2b2ce2fadc552d02b4af6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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)))