-
-
Save amalloy/1996359 to your computer and use it in GitHub Desktop.
Rate limit clojure fn
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 rate-limit [interval s] | |
(let [cache (atom {})] | |
(for [x s | |
:let [t (System/currentTimeMillis)] | |
:when (< (+ (get @cache x 0) interval) t)] | |
(do (swap! cache assoc x t) | |
x)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment