diff --git a/src/clj/com/rpl/specter.cljx b/src/clj/com/rpl/specter.cljx index b712ce2..37427ba 100644 --- a/src/clj/com/rpl/specter.cljx +++ b/src/clj/com/rpl/specter.cljx @@ -528,9 +528,21 @@ (defpathedfn if-path "Like cond-path, but with if semantics." - ([cond-p if-path] (cond-path cond-p if-path)) - ([cond-p if-path else-path] - (cond-path cond-p if-path nil else-path))) + ([cond-p then-path] + (fixed-pathed-nav [late-cond cond-p + late-then then-path] + (select* [this structure next-fn] + (i/if-select structure next-fn late-cond late-then STOP)) + (transform* [this structure next-fn] + (i/if-transform structure next-fn late-cond late-then STOP)))) + ([cond-p then-path else-path] + (fixed-pathed-nav [late-cond cond-p + late-then then-path + late-else else-path] + (select* [this structure next-fn] + (i/if-select structure next-fn late-cond late-then late-else)) + (transform* [this structure next-fn] + (i/if-transform structure next-fn late-cond late-then late-else))))) (defpathedfn multi-path "A path that branches on multiple paths. For updates, diff --git a/src/clj/com/rpl/specter/impl.cljx b/src/clj/com/rpl/specter/impl.cljx index 02f63a3..9c21e9f 100644 --- a/src/clj/com/rpl/specter/impl.cljx +++ b/src/clj/com/rpl/specter/impl.cljx @@ -709,6 +709,20 @@ res )))))) +(defn if-select [structure next-fn late-cond late-then late-else] + (let [apath (if (empty? (compiled-select* late-cond structure)) + late-else + late-then)] + (doall (mapcat next-fn (compiled-select* apath structure))) + )) + +(defn if-transform [structure next-fn late-cond late-then late-else] + (let [apath (if (empty? (compiled-select* late-cond structure)) + late-else + late-then)] + (compiled-transform* apath next-fn structure) + )) + (defn filter-select [afn structure next-fn] (if (afn structure) (next-fn structure)))