Skip to content

Instantly share code, notes, and snippets.

@amalloy amalloy/gist:848084 forked from ray1729/gist:848069
Created Feb 28, 2011

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
You can’t perform that action at this time.