34 lines
499 B
Clojure
34 lines
499 B
Clojure
(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))
|
|
|
|
(defn replace-by [xs f x]
|
|
(mapv
|
|
(fn [t]
|
|
(if (= (f t) (f x))
|
|
x
|
|
t))
|
|
xs))
|
|
|
|
(defn dollars-0? [amt]
|
|
(< -0.001 amt 0.001))
|
|
|
|
(defn dollars= [amt1 amt2]
|
|
(dollars-0? (- amt1 amt2) ))
|