@Kevin, yes, I did just that to test coll-reduce, thanks for helping me out!

@Alex, thanks for the detailed response, it sure demystified this error and 
gave a bunch of different solutions, awesome!


On Monday, March 7, 2016 at 5:17:45 PM UTC-8, Alex Miller wrote:
>
> Iterator, seqs, and chunking is indeed the key to this issue. The change 
> in question is http://dev.clojure.org/jira/browse/CLJ-1669, which made 
> iterator-seq's chunked. In general, this should not be problematic with 
> most Java iterators, however there is a iterator implementation pattern 
> where the identical object is returned (and mutated) on every call to 
> next() on the iterator. This is done in Java for performance reasons 
> (reuses a single mutable object rather than creating N objects). Because 
> iterator-seq now chunks, it will obtain 32 elements at a time, but they 
> will all be the identical object, so you'll see the state of the 32'nd 
> object for all of them.
>
> iterator-seq intentionally does not handle this iterator pattern (this is 
> in the docstring and was introduced via 
> http://dev.clojure.org/jira/browse/CLJ-1738). 
>
> If you need to control iteration to one at a time (non-chunked), then 
> there are several options:
>
> 1. Use loop/recur and explicitly handle each object one at a time. Sounds 
> like you've got that one.
>
> 2. Implement your own lazy-seq that does not chunk.
>
> (defn iter-seq [iter f]
>   (if (.hasNext iter)
>     (lazy-seq
>       (cons (f (.next iter))
>             (iter-seq iter f)))))
>
> 3. Use transducers which will also pull a single element at a time in 
> current transducible contexts. If you want to use it as a seq, this means 
> invoking 
>
> (defn transform [^ArchiveRecord r]
>   (let [header (.getHeader r)
>          mime (.getMimetype header)]
>     (if (plain-text? mime)
>       (println "got " (.available r)))))
>
> (defn mapper-map [this ^Text key warc-value ^MapContext context]
>   (sequence (map transform) warc-value))
>
> 4. In this particular case, since you're only doing side effects, 
> something like dorun would maybe be better.
>
> 5. (WARNING - may be removed!) You can still access the old iterator-seq 
> impementation in the Java impl for now:
>
> (clojure.lang.IteratorSeq/create iter)
>
>
>

-- 
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.

Reply via email to