That is, had flattening actually been your goal. It seem like you didn't really want to throw out that structure, just transform it, so flattening is irrelevant I guess other than the subject line. :)
On Mon, Feb 21, 2011 at 5:34 PM, rob levy <r.p.l...@gmail.com> wrote: > One way to approve the problem is to write a function to convert the nested > maps into nested seqs. Once it is in that form you can use flatten on it and > partition the flat list as you like: > > (defn flatten-maptree [m] > (letfn [(maptree->seqtree > [m] > (lazy-seq > (cond > (map? m) (map #(cons > (key %) > (maptree->seqtree (val %))) > m) > :else [m])))] > (flatten (maptree->seqtree m)))) > > > user=> (partition 4 (flatten-maptree {1 {2 {3 4 5 6} 7 {8 9}}})) > ((1 2 3 4) (5 6 7 8)) > > > On Mon, Feb 21, 2011 at 3:25 PM, James Reeves <jree...@weavejester.com>wrote: > >> On 21 February 2011 07:17, Damien <damienlep...@gmail.com> wrote: >> > Not sure if I should talk about flattening but basically I'm trying to >> > achieve the following transformation: >> > >> > user=>(flatten-tree {1 {2 {3 4 5 6} 7 {8 9}}}) >> > ((1 2 3 4) (1 2 5 6) (1 7 8 9)) >> > >> > Any suggestion? >> >> (defn flatten-tree [t] >> (if (map? t) >> (for [[k v] t, w (flatten-tree v)] >> (cons k w)) >> (list (list t)))) >> >> In this case, I think using protocols would be over-engineering. We >> can always add protocols in later if we happen to need them. That's >> one of the benefits of protocols as compared to Java's interfaces. >> >> - James >> >> -- >> 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 >> > > -- 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