clojure - Execute a vector of functions doesn't work when fns are passes as params -


this code doesn't work indended:

(((fn [& fns]     (fn [& params]       (reduce #(%2 %1) params fns)))   rest reverse)  [1 2 3 4]) ;; => () instead of (3 2 1) 

is there way fix change inside #(%2 %1)?

i think question equivalent to: how convert (#<core$rest>) (rest)?

note: process solve http://www.4clojure.com/problem/58 i've seen other solutions curious specific implementation.

try using [params] rather [& params], so:

(fn [params] (reduce #(%2 %1) params fns)) 

the [& params] argument taking collection [1 2 3 4] , wrapping again, in list, giving ([1 2 3 4]) seed reduce function.

if wanted change inside #(%2 %1) need unwrap ([1 2 3 4]), first time. see if first returned collection, (coll? (first %1)), , call (first %1), otherwise leave %1 is. seems convoluted , won't work other input data though.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -