Re: in-smaller-lists
Cool, I thought it must exist somewhere, but the 3 3 nil is, although obviously enabling, strange for what I would think should be default behavior. I'll just go ahead and use (def in-smaller-lists #(partition %1 %1 nil %2)) Thanks for the tip. On Sep 25, 8:24 pm, Jeff Valk jv-li...@tx.rr.com wrote: On Friday 25 September 2009 at 08:46 pm, Travis wrote: I'm doing some file streaming with a lazy list and I ran into a problem where I had to process a whole chunk at a time, so I wrote this function. Just posting to see if I'm reinventing something or if it might be a good addition to contrib. (defnin-smaller-lists[the-list smaller-list-size] ... Example: user= (in-smaller-lists(range 11) 3) ((0 1 2) (3 4 5) (6 7 8) (9 10)) How about: user= (partition 3 3 nil (range 11)) ((0 1 2) (3 4 5) (6 7 8) (9 10)) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
in-smaller-lists
I'm doing some file streaming with a lazy list and I ran into a problem where I had to process a whole chunk at a time, so I wrote this function. Just posting to see if I'm reinventing something or if it might be a good addition to contrib. (defn in-smaller-lists [the-list smaller-list-size] (lazy-seq (let [[fnbr the-rest] (split-at smaller-list-size the-list)] (if (first the-rest) (cons fnbr (in-smaller-lists the-rest smaller-list-size)) (list fnbr)) ))) Example: user= (in-smaller-lists (range 11) 3) ((0 1 2) (3 4 5) (6 7 8) (9 10)) I do database work and this is very useful for processing a csv n rows at a time. Travis --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: in-smaller-lists
On Friday 25 September 2009 at 08:46 pm, Travis wrote: I'm doing some file streaming with a lazy list and I ran into a problem where I had to process a whole chunk at a time, so I wrote this function. Just posting to see if I'm reinventing something or if it might be a good addition to contrib. (defn in-smaller-lists [the-list smaller-list-size] ... Example: user= (in-smaller-lists (range 11) 3) ((0 1 2) (3 4 5) (6 7 8) (9 10)) How about: user= (partition 3 3 nil (range 11)) ((0 1 2) (3 4 5) (6 7 8) (9 10)) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---