Using partition-by will give you a lazy sequence. (defn only-keep-unique-ids [ids] (map first (partition-by #(get-form-id-without-timestamp %) ids)))
On Saturday, 26 July 2014 07:32:43 UTC+10, Christopher Elwell 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.