Rowdy's question asks for less than what core/distinct delivers--he only wanted to remove *adjacent* duplicates.

That said, core/distinct is a better demo of "how do I maintain state across a lazy sequence without requiring any mutation?"

Stu

Hi,

On Feb 18, 3:04 pm, Rowdy Rednose <rowdy.redn...@gmx.net> 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 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 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

Reply via email to