Skip to content

Instantly share code, notes, and snippets.

@simon-brooke
Created June 5, 2025 11:28
Show Gist options
  • Save simon-brooke/6d71cbfa46549fd558e84b06e583f5bd to your computer and use it in GitHub Desktop.
Save simon-brooke/6d71cbfa46549fd558e84b06e583f5bd to your computer and use it in GitHub Desktop.
Map, but with a delay
(defn map-interval
"Like `map` -- apply function `f` to each element in `col` in turn and
return the values returned in sequence, but in a single thread and pausing
between each invocation of `f`.
Useful for example in circumstances where you're querying a rate-limited
service."
[f col interval]
(let [a (atom ())]
(doseq [x col]
(Thread/sleep interval)
(swap! a conj (f x)))
(reverse (deref a))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment