(ns auto-ap.utils)

(defn by
  ([f xs]
   (by f identity xs))
  ([f fv xs]
   (reduce
    #(assoc %1 (f %2) (fv %2))
    {}
    xs)))

(defn replace-if [f candidate existing]
  (reduce
   (fn [xs x]
     (if (f x candidate)
       (conj xs candidate)
       (conj xs x)))
   []
   existing))
