Beautiful solution, I got a lot out of it.
Thanks Juha!

--
Ambrose

On Thu, May 5, 2011 at 10:08 PM, Juha Arpiainen <jarpi...@gmail.com> wrote:

> (defn add-path [h path]
>  (let [dir (butlast path)
>        entry (last path)]
>    (update-in h dir (fn [x] (if x (conj x entry) [entry])))))
>
> (defn restore-hierarchy [paths]
>  (reduce add-path {} paths))
>
> Then
>
> (restore-hierarchy [["top" "level" "file1"] ["top" "level" "file2"]
> ["top" "level2" "file3"]])
> => {"top" {"level2" ["file3"], "level" ["file1" "file2"]}}
>
> --
> Juha Arpiainen
>
> On May 5, 3:40 pm, Steffen <steffen.die...@gmail.com> 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...
> >
> > Thanks,
> >
> > Steffen
>
> --
> 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

Reply via email to