idiomatic super-map
This is probably a pretty newb question...sorry. I'm looking for the idiomatic way to apply a seq of functions to other seqs. In other words, a version of map that doesn't take a single f, but a seq of them. (map f c1 c2 ... cn) = ((f c11 c21 ... cn1) (f c12 c22 ... cn2) ... (f c1m c2m ... cnm)) (supermap fs c1 c2 ... cn) = ((f1 c11 c21 ... cn1) (f2 c12 c22 ... cn2) ... (fk c1m c2m ... cnm)) Make sense? Before I go reinventing the wheel (map implementation looks hard!), I figured I would ask here...somebody must be doing this already. Thanks in advance. Mike -- 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
Re: idiomatic super-map
Hi, (map (juxt f1 f2 f3) c1 c2 c3) (map (apply juxt fs) c1 c2 c3) (apply map (apply juxt fs) cs) Sincerely Meikel -- 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
Re: idiomatic super-map
Or maybe on a second look: (map apply fs c1 ... cn)? (user= (map #(apply %1 %) [+ - *] [1 2 3] [1 2 3]) (2 0 9) vs. user= (map (juxt + - *) [1 2 3] [1 2 3]) ([2 0 1] [4 0 4] [6 0 9]) Sincerely Meikel -- 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
Re: idiomatic super-map
On Fri, Feb 4, 2011 at 9:19 AM, Mike cki...@gmail.com wrote: This is probably a pretty newb question...sorry. I'm looking for the idiomatic way to apply a seq of functions to other seqs. In other words, a version of map that doesn't take a single f, but a seq of them. (map f c1 c2 ... cn) = ((f c11 c21 ... cn1) (f c12 c22 ... cn2) ... (f c1m c2m ... cnm)) (supermap fs c1 c2 ... cn) = ((f1 c11 c21 ... cn1) (f2 c12 c22 ... cn2) ... (fk c1m c2m ... cnm)) Make sense? This does it without using juxt: (defn supermap [fs cs] (map apply fs (apply map vector cs))) With juxt it's as Meikel wrote: (defn supermap [fs cs] (apply map (apply juxt fs) cs)) user= (supermap [#(* %1 %2) #(* %1 %2 %2) + -] [1 2 3 4] [5 6 7 8]) (5 72 10 -4) -- 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
Re: idiomatic super-map
On Fri, Feb 4, 2011 at 10:11 AM, Ken Wesson kwess...@gmail.com wrote: With juxt it's as Meikel wrote: (defn supermap [fs cs] (apply map (apply juxt fs) cs)) Or not. Hm, juxt documentation needs clarifying. (defn supermap [fs cs] (map apply fs (apply map vector cs))) -- 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
Re: idiomatic super-map
On Feb 4, 10:11 am, Ken Wesson kwess...@gmail.com wrote: This does it without using juxt: (defn supermap [fs cs] (map apply fs (apply map vector cs))) This is really nice. Even handles infinity properly: (supermap (repeat +) (range 3) (range 3)) = (0 2 4) Thanks Ken and Meikel! Mike -- 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