Hi everybody, while the partition-by by itself is lazy the subseqs it creates are not lazy. I was attempting to make that happen. I would like to get comments from the community about my modification to partition-by so as to make it create the subsequences in a lazy way ... will this work?
My version : (defn lazy-partition-by "Applies f to each value in coll, splitting it each time f returns a new value. Returns a lazy seq of partitions." {:added "1.2"} [f coll] (lazy-seq (when-let [s (seq coll)] (let [fst (first s) fv (f fst) run (lazy-seq (cons fst (take-while #(= fv (f %)) (next s))))] (cons run (lazy-partition-by f (drop-while #(= fv (f %)) s))))))) original version : (defn partition-by "Applies f to each value in coll, splitting it each time f returns a new value. Returns a lazy seq of partitions." {:added "1.2"} [f coll] (lazy-seq (when-let [s (seq coll)] (let [fst (first s) fv (f fst) run (cons fst (take-while #(= fv (f %)) (rest s)))] (cons run (partition-by f (drop (count run) s))))))) thanks. Sunil. -- 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