Created
June 5, 2025 11:28
-
-
Save simon-brooke/6d71cbfa46549fd558e84b06e583f5bd to your computer and use it in GitHub Desktop.
Map, but with a delay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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