Skip to content

Instantly share code, notes, and snippets.

@jooyunghan
Last active November 4, 2015 15:10
Show Gist options
  • Save jooyunghan/39f3f02d935426a3e440 to your computer and use it in GitHub Desktop.
Save jooyunghan/39f3f02d935426a3e440 to your computer and use it in GitHub Desktop.
Throttle-first operator which ignores the following events with same key within `duration`
(defn throttle-first [duration keyF]
(operator*
(fn [s]
(let [cache (atom #{})]
(subscriber
s
(fn [s v]
(let [k (keyF v)]
(when-not (@cache k)
(on-next s v)
(swap! cache conj k)
(set-timeout #(swap! cache disj k) duration)))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment