clojure: (apply fn coll) vs (apply #(apply fn %&) coll)
clojure
Solution
No, there is no difference. There is no reason to write the longer form; I can only assume it was arrived at by gradual changes to code that made sense at one time.
Problem
I am working my way through labrepl and I saw some code that follows this pattern: ``` ;; Pattern (apply #(apply f %&) coll) ;; Concrete example user=> (apply #(apply + %&) [1 2 3 4]) 10 ``` This seems to be equivalent to this pattern: ``` ;; Pattern (apply f coll) ;; Concrete example user=> (apply + [1 2 3 4]) 10 ``` Are these patterns equivalent? If not, what's the difference and when would you use one over the other? I took the former pattern from the step function in the cellular-automata lab of labrepl: ``` (defn step "Advance the automation by one step, updating all cells." [board] (doall (map (fn [window] (apply #(apply map brians-brain-rules %&) (doall (map torus-window window)))) (torus-window board)))) ``` Update: I added a concrete example of each pattern to help make the question clearer.