Instantly share code, notes, and snippets.

What would you like to do?
;; not sure whether this is an improvement but I don't really like letfn
(defn keep-only
[n bucket-fn s]
((fn my-filter
[s seen]
(when (seq s)
(let [e (first s)
b (bucket-fn e)
c (inc (get seen b 0))]
(if (> c n)
(my-filter (rest s) seen)
(cons e (my-filter (rest s) (assoc seen b c))))))))
s {}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment