Clojure sleep flow between score cards

I have a block of code that I need to execute in Clojure that looks like this:

    (map function coll)

However, I need to delay the time interval between each subsequent function call. That is, I want to call the functionfirst element, then sleep for 10 seconds, then call with the second element, etc.

How can I do that?

Thanks in advance for your help.

+4
source share
1 answer

Just for completeness, after discussing in the comments, this is what an implementation using doseqwould look like wrapped up in a neat little function:

(defn doseq-interval
  [f coll interval]
  (doseq [x coll]
    (Thread/sleep interval)
    (f x)))

And so what would you call it:

(doseq-interval prn (range 10) 1000)
+9
source

All Articles