On Thu, Apr 7, 2011 at 8:56 AM, Baishampayan Ghose <b.gh...@gmail.com> wrote: >> Given a collection of functions >> >> (def fs [#(* % 10) #(+ % 1)]) >> >> and some numbers >> >> (def c [1 2 3]) >> >> How do I apply all the functions to c so that the results of one >> function are passed to the other. In the same way -> works. Thus in >> this case the expected result would be: 11 21 31 > > A typical use-case for map & comp - > > (map (apply comp (reverse fs)) c) > ; => (11 21 31)
Or if you don't want to use reverse: (map #(reduce (fn [x f] (f x)) % fs) c) Hm, BG's solution compiles no new classes, while mine generates two. More classes is better, right? :-P --Chouser http://joyofclojure.com/ -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en