On Thu, May 05, 2011 at 05:40:02AM -0700, Steffen wrote:
> Hello,
> 
> I'm trying to come up with a way to recreate a directory hierarchy. Entries
> within zip archives are just flat strings like "top/level/file1", but I would
> like to operate on them hierarchically. So my problem could be stated as:
> If
> 
>   (restore-hierarchy [["top" "level" "file1"] ["top" "level" "file2"] ["top"
> "level2" "file3"]])
> 
> returns
> 
>   {"top" {"level" ("file1" "file2"), "level2" ("file3")}}
> 
>  what does a nice definition of #'restore-hierarchy look like? Sadly my own
> attempts to hack it are too embarrassing to post them here...

Here's my version using `clojure.contrib.map-utils/deep-merge-with`:

    (use '[clojure.contrib.map-utils
           :only [deep-merge-with]])

    (defn file-path [[first & rest]]
      (if rest
        {first (file-path rest)}
        first))

    (defn restore-hierarchy [x]
      (->> x
           (map file-path)
           (apply deep-merge-with list)))

Syntax highlighted: https://gist.github.com/957202

--
Timo

-- 
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

Reply via email to