Clojure: Call a function for each element in a vector with it index

Viewed 20195

Say I have a vector:

(def data ["Hello" "World" "Test" "This"])

And I want to populate a table somewhere that has an api:

(defn setCell
  [row col value]
  (some code here))

Then what is the best way to get the following calls to happen:

(setCell 0 0 "Hello")
(setCell 0 1 "World")
(setCell 0 2 "Test")
(setCell 0 3 "This")

I found that the following will work:

(let [idv (map vector (iterate inc 0) data)]
  (doseq [[index value] idv] (setCell 0 index value)))

But is there a faster way that does not require a new temporary datastructure idv?

5 Answers
Related