The first of the following two functions, fn-apply-cmp-vals, returns a partial function that is used in the second function, apply-cmp-vals.
What is the correct syntax to embed fn-apply-cmp-vals as an anonymous function in apply-cmp-vals?
(defn fn-apply-cmp-vals
[fn cmp-sos cmp-idx]
(partial fn cmp-sos cmp-idx))
(defn apply-cmp-vals
[cmp-vec cmp-vals cmp-vec-idx]
(let [fn-cmp (fn-apply-cmp-vals ret-non-match-rows cmp-vec cmp-vec-idx)]
(map #(fn-cmp %1) cmp-vals)))
Specifically, I want to replace fn-apply-cmp-vals ret-non-match-rows cmp-vec cmp-vec-idx) with an anonymous function instead of a function call.
Thank You.
Lets take a look at this, in detail, one step at a time.
Your goal is to inline
fn-apply-cmp-valsas an anonymous function inapply-cmp-vals. So lets do that first. Here is what your function looks like with no other changes:This accomplishes your goal, but there is room for improvement. Since your function simply calls
partialwith the given arguments, lets replace the anonymous function with a direct call topartialwith the correct arguments. This works becausepartialreturns a partially applied function.Now, lets look where
fn-cmpis used. It is being called in its own anonymous function with a single argument. Since your partial function satisfies this requirement, you could instead just passfn-cmpinto the map function directly.Finally, if you desire, you can completely remove the
letform:So it turns out you didn’t need an anonymous function at all!