Thanks! I was playing around with similar variants last night & came up with
some that seem to work for one element, but not many.
I was seeing a similar result from your version:
=> (map2 count [(repeat 1e8 "stuff") (repeat 1e8 "stuff") (repeat 1e8
"stuff")])
OutOfMemoryError GC overhead limi
At least in your particular case, replacing map with map2, defined below as
a small modification to a subset of map, seems to do the trick:
(defn map2 [f coll]
(lazy-seq
(when-let [s (seq coll)]
(let [r (rest s)]
(cons (f (first s)) (map2 f r))
(map2 count [(repeat 1e8 "stuff
Ran into an interesting problem today. In short, this works:
(count (repeat 1e8 "stuff"))
But this doesn't:
(map count [(repeat 1e8 "stuff")])
To be fair, given sufficient memory, it would eventually complete. (If the
second example does work for you, change it to 1e10 or something higher).