Love it. Much more readable without any nasty persistent state. On Friday, 10 January 2014 15:19:03 UTC, Ray Miller wrote: > > On 10 January 2014 14:59, Colin Yates <colin...@gmail.com <javascript:>>wrote: > >> I have a sequence of file names and I want to make them unique. >> (uniquify ["a" "b" "c" "a"]) => ["a" "b" "c" "a_1"]) >> >> This is what I have come up with, but surely there is a better way? >> >> > I would do something like: > > (defn uniquify > ([xs] > (uniquify xs (fn [x n] (str x "_" n)))) > ([xs formatter] > (letfn [(uniquify* [xs seen] > (lazy-seq > (when (not-empty xs) > (let [x (first xs) > n (seen x 0)] > (if (> n 0) > (cons (formatter x n) (uniquify* (rest xs) (assoc > seen x (inc n)))) > (cons x (uniquify* (rest xs) (assoc seen x (inc > n)))))))))] > (uniquify* xs {})))) >
-- -- 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/groups/opt_out.