diff --git a/src/clj/com/rpl/specter.cljx b/src/clj/com/rpl/specter.cljx index 37427ba..4dab990 100644 --- a/src/clj/com/rpl/specter.cljx +++ b/src/clj/com/rpl/specter.cljx @@ -503,29 +503,6 @@ (collect-val [this structure] val )) -(defpathedfn cond-path - "Takes in alternating cond-path path cond-path path... - Tests the structure if selecting with cond-path returns anything. - If so, it uses the following path for this portion of the navigation. - Otherwise, it tries the next cond-path. If nothing matches, then the structure - is not selected. - - The input paths may be parameterized, in which case the result of cond-path - will be parameterized in the order of which the parameterized navigators - were declared." - [& conds] - (variable-pathed-nav [compiled-paths conds] - (select* [this structure next-fn] - (if-let [selector (i/retrieve-cond-selector compiled-paths structure)] - (->> (compiled-select selector structure) - (mapcat next-fn) - doall))) - (transform* [this structure next-fn] - (if-let [selector (i/retrieve-cond-selector compiled-paths structure)] - (compiled-transform selector next-fn structure) - structure - )))) - (defpathedfn if-path "Like cond-path, but with if semantics." ([cond-p then-path] @@ -544,6 +521,25 @@ (transform* [this structure next-fn] (i/if-transform structure next-fn late-cond late-then late-else))))) +(defpathedfn cond-path + "Takes in alternating cond-path path cond-path path... + Tests the structure if selecting with cond-path returns anything. + If so, it uses the following path for this portion of the navigation. + Otherwise, it tries the next cond-path. If nothing matches, then the structure + is not selected. + + The input paths may be parameterized, in which case the result of cond-path + will be parameterized in the order of which the parameterized navigators + were declared." + [& conds] + (let [pairs (reverse (partition 2 conds))] + (reduce + (fn [p [tester apath]] + (if-path tester apath p)) + STOP + pairs + ))) + (defpathedfn multi-path "A path that branches on multiple paths. For updates, applies updates to the paths in order." diff --git a/src/clj/com/rpl/specter/impl.cljx b/src/clj/com/rpl/specter/impl.cljx index 9c21e9f..0f07dec 100644 --- a/src/clj/com/rpl/specter/impl.cljx +++ b/src/clj/com/rpl/specter/impl.cljx @@ -695,20 +695,6 @@ (next-fn structure) )) -(defn retrieve-cond-selector [cond-paths structure] - (let [aseq (seq cond-paths)] - (if aseq - (loop [s aseq] - (let [tester (first s) - s2 (next s) - res (first s2)] - (if (empty? (compiled-select* tester structure)) - (let [s3 (next s2)] - (if s3 (recur s3)) - ) - res - )))))) - (defn if-select [structure next-fn late-cond late-then late-else] (let [apath (if (empty? (compiled-select* late-cond structure)) late-else