Hi,

I wrote a function to trackdown a path in a vector containing nested maps:

(defn get-files-from-folder-path [ffs folder-path]
  (filter #(= :file (:type %))
          (loop [tree-path-position 0 acc [] fof ffs]
            (let [folder (first (filter #(and
                                          (= :folder (:type %))
                                          (= (nth folder-path 
tree-path-position nil) (:name %))) fof))]
              (if (not (:children folder))
                acc
                (recur (inc tree-path-position)
                       (if (= (+ tree-path-position 1) (count folder-path)) 
(concat acc (:children folder)) acc)
                       (:children folder)))))))

And these are the inputs:
(def ffs [{:type :folder, :name "sub1", :children [{:type :file, :name 
"datomic-data.edn"}]} 
          {:type :folder, :name "sub2", :children [{:type :file, :name "foo 
(1).csv"} 
                                                   {:type :folder, :name 
"sub21", :children [{:type :file, :name "lein-env"}]}]}])

(def tree-path ["sub2" "sub21"])

And I call it like this:

(get-files-from-folder-path ffs tree-path)

Is there a way to use reduce for that? I was stuck because I think I have to 
reduce on two lists here, 
but reduce only takes one to start with, thats why I chose the loop / recur 
route. Which works
but it looks ugly to me and I am afraid in one week I want understand it 
anymore.

Thanks Regards,
Sven



-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to