That works nicely, even for infinite sequences, but appears to hang on to the head:
user=> (split [2000 2001] (repeatedly #(int-array 102400))) java.lang.OutOfMemoryError: Java heap space The map/nth variant has this same problem, unfortunately. My original version works around these issues at the expense of being longer and uglier ;o) Mark CuppoJava <[email protected]> writes: > I see. Thanks for explaining. > > If speed is an issue, and if you can assume that indices are properly > sorted in ascending order, I believe this looks like a lazy-reduce > problem. Clojure has no lazy-reduce (or does it?) so I've written my > own: > > (defn lazy_reduce [f val coll] > (lazy-seq > (if (seq coll) > (let [val (f val (first coll))] > (cons val (lazy_reduce f val (rest coll))))))) > > (defn split [indices coll] > (map first > (lazy_reduce nthnext coll > (map - indices (cons 0 indices))))) -- Mark Triggs <[email protected]> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
