Looking at what you are asking, I would say that one way to do this is to build a function that looks something like this:
(pred-map {:a [some-test-fn "one-value" "other-value"] :b [some-test-fn 15 25] :c [different-test :one :two]} xy)
where x is the argument for all references of the first exchange function and y to the second
a way to achieve this may be as follows:
(defn get-value [p tv fv a] (if (pa) tv fv)) (defn get-predicate-set [m] (set (map first (vals m)))) (defn get-arg-map [m args] (zipmap (get-predicate-set m) args)) (defn get-arg [pm args] ((get-arg-map m args) p)) (defn get-key-value-pair-creator [m args] (fn [[k [p tv fv]]] [k (get-value p tv fv (get-arg pm args))])) (defn pred-map [m & args] (into {} (map (get-key-value-pair-creator m args) m)))
However, these functions rely on arguments that map functions to the principle of equality (which seems to go with references), so it will not understand two equal anonymous functions as one and the same.
if you don't mind repeating the arguments you create, a simpler function is as follows:
(pred-map {:a [(some-test-fn x) "one value" "other-value"] :b [(some-test-fn x) 15 25] :c [(different-test y) :one :two]})
following a simple function:
(defn pred-map [m] (into {} (for [[k [p tv fv]] m] [k (if p tv fv)])))
or in an inconsolable style:
(def pred-map (comp (partial into {}) (partial map (fn [[k [p tv fv]]] [k (if p tv fv)]))))
source share