I'd probably write this like so, fwiw (parameterized by the transformation function):
user> (defn only-keep-unique-ids [id-transform ids] (map first (vals (group-by id-transform ids)))) #'user/only-keep-unique-ids user> (only-keep-unique-ids (partial take 2) ["aaa" "baa" "xsdf" "aa3" "ba4" "azx" "aa4" "xsss"]) ("aaa" "baa" "xsdf" "azx") it's not lazy, though. On Fri, Jul 25, 2014 at 2:32 PM, Christopher Elwell < elwell.christop...@gmail.com> wrote: > New to Clojure, how is this function that I wrote? Any suggestions for > improvement; is it too complicated? > > It filters a sequence, leaving only the first occurrence of each item in > the seq that has a matching prefix (get-form-id-without-timestamp gets > just the id prefix). > > (defn only-keep-unique-ids [ids] > (let [seen-ids (atom #{}) > filter-fn #(let [raw-form-id (get-form-id-without-timestamp %) > is-unique (not (contains? @seen-ids raw-form-id))] > (do (swap! seen-ids conj raw-form-id) > is-unique))] > (filter filter-fn ids))) > > > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Ben Wolfson "Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure." [Larousse, "Drink" entry] -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.