Skip to content

Instantly share code, notes, and snippets.

@amalloy
Forked from ray1729/gist:848069
Created February 28, 2011 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/848084 to your computer and use it in GitHub Desktop.
Save amalloy/848084 to your computer and use it in GitHub Desktop.
;; 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]
(lazy-seq
(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