Hi, On Feb 18, 3:04 pm, Rowdy Rednose <[email protected]> wrote:
> "Returns a lazy sequence of the items in coll for which (pred item) > returns true. pred must be free of side-effects." > > So that means I should not write a function like this: > > (defn unique [sc] > "Returns a lazy sequence with all consecutive duplicates removed" > (let [last (atom (Object.))] > (filter #(let [ok (not= @last %)] (reset! last %) ok) sc))) > > user=> (unique [1 2 3 3 4 5 5 6]) > (1 2 3 4 5 6) > > But in contrast to functions that can be retried (compare-and-swap > etc.), I don't immediately see why having side effects in filter would > be bad. Can anybody enlighten me? And how should I do this instead? Besides the other suggestions: clojure.core/distinct and its implementation. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
