There are some other questions on this topic but I could not get an answer from reading them. What I want to do is use Apply on some of the arguments of a function, h, and then Map on another argument. Here is what I attempted:
Map[Apply[{h[#, ##]} &, {a, b}] &, {1, 2}]
(* ===>{{h[a, a, b]}, {h[a, a, b]}} *)
The elements I want to Map over never get used.
But this is not what I want. I want just
{h[1,a,b],h[2,a,b]}
I could use Table instead of Map but it's slow (slower than just using Apply twice) and I was hoping Map would be faster.
I understand that Apply is using both # and ## but I'm not sure what syntax is correct to force the first Slot to be used by Map instead of Apply.
EDIT: This is more like what I actually want to do:
Map[Apply[{h1[#, ##],h2[#, ##]} &, {RandomReal[], RandomReal[]}] &, {1, 2}]
So I want output as
{{h1[1, a1,b1], h2[1, a1,b1]},{h1[2, a2,b2], h2[2, a2,b2]}}
where I a's and b's are the random numbers. So to get this, I think the order of Apply and Map is important.
Sequence @@ {a, b}to preserve the input in the given form ? – b.gates.you.know.what Dec 12 '12 at 16:56{1, 2}and{a, b}? – Mr.Wizard Dec 12 '12 at 17:00