On 21 February 2011 07:17, Damien <[email protected]> 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 [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

Reply via email to