I have a long, lazy sequence that I want to reduce and test lazily. As soon as two sequential elements are not = (or some other predicate) to each other, I want
I found this post while hitting a time limit on a 4clojure problem and I found another way to avoid the 32-chunks:
;; add another dummy sequence parameter to the map:
(apply = (map #(do (prn %2) %) (range) (range)))
The higher arity forms of map don't appear to use chunked sequences (clojure 1.5)
You have to do something with the second parameter, so being explicit about that might be better:
(apply = (map (fn [i _] (prn i) i) (range) (range)))
This isn't as neat as the other solutions but might be good for quick and dirty uses, like testing "is this slow because of chunking?".
Regarding apply, you could use partition to get pairs from the sequence and = them:
(every? #(apply = %) (partition 2 1
(map (fn [i _] (prn i) i) (range) (range))))
Although reducep looks useful too.
PS. I don't want to give the impression that the chunked sequence is slower, it's not. My issue is that the 4clojure test case calls "first" on my seq generating function over a range of values, so chunking means I do 32 times the work. (PPS. My code is still too slow)