Fork me on GitHub
#specter
<
2017-05-23
>
madstap01:05:48

@dottedmag I would just use core functions:

(defn assoc-file [dir-map path content]
  (let [xs (str/split path #"/")
        dirs (butlast xs)
        file-name (last xs)
        path-vec (-> (interleave (repeat :dirs) dirs)
                     vec
                     (conj :files file-name))]
    (assoc-in dir-map path-vec content)))

(assoc-file {} "foo/bar/baz.sh" "#!/bin/bash\n\necho foobar")
Edit: (mapcat vector foo bar) is just (interleave foo bar)

dottedmag18:05:15

@madstap Thanks. I've got other operations on the same structure, so I went slightly crazy and created https://github.com/dottedmag/azip

madstap19:05:44

dottedmag: Nice. I've never used zippers before. Out of curiosity, how would my assoc-file function look using azip?