Re: Use reduce or something appropriate instead of loop / recur

2015-03-24 Thread Sven Richter
Thank you very much. I had the feeling I should reduce over the tree-path, but was not able to come up with something good like you did. Best Regards, Sven Am Dienstag, 24. März 2015 22:58:18 UTC+1 schrieb Francis Avila: > > Notice that get-in-via is simply reduce: > > (defn get-in-via [m via ks

Re: Use reduce or something appropriate instead of loop / recur

2015-03-24 Thread Francis Avila
Notice that get-in-via is simply reduce: (defn get-in-via [m via ks] (reduce (fn [m' k] (via m' k)) m ks)) Same as: (defn get-in-via [m via ks] (reduce via m ks)) Same as: (reduce via m ks) So once you write your "step" function, traversal is taken care of by the reduction. On Tues

Re: Use reduce or something appropriate instead of loop / recur

2015-03-24 Thread Francis Avila
Separate out traversal from selection to make this clearer. We make a generic traversal function get-in-via. It accepts a via function which takes the current result and some value which determines the next result, and returns the next result. (defn get-in-via [m via ks] (reduce (fn [m' k] (v

Use reduce or something appropriate instead of loop / recur

2015-03-24 Thread Sven Richter
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