7
$\begingroup$

I want to produce {Foo[a,b, c], Goo[a, b, c], Hoo[a, b, c]}. However my attempt below

Thread[Apply[{Foo, Goo, Hoo}, HoldComplete@Sequence[a, b, c]]]

produces {Foo, Goo, Hoo}[a, b, c].

Could you fix it?

$\endgroup$
3
  • $\begingroup$ Construct[#, Sequence[a,b,c]] & /@ {Foo, Goo, Hoo} ... or if you want to keep the hold and release: ReleaseHold[Construct[#, HoldComplete@Sequence[x, y, z]] & /@ {Foo, Goo, Hoo}] $\endgroup$
    – flinty
    Jun 11, 2020 at 0:45
  • $\begingroup$ Let me know if my solution would work for you, or how I might improve it :D $\endgroup$ Jun 11, 2020 at 0:55
  • $\begingroup$ @flinty: Thank you. $\endgroup$ Jun 11, 2020 at 3:00

5 Answers 5

11
$\begingroup$

Consider Through:

Through[{Foo, Goo, Hoo} @@ {a, b, c}]
{Foo[a, b, c], Goo[a, b, c], Hoo[a, b, c]}

Alternatively, use it as:

Through @ {Foo, Goo, Hoo}[a, b, c]
{Foo[a, b, c], Goo[a, b, c], Hoo[a, b, c]}

Or make it into a function:

boohoo = Through[# @@ #2] &;

{Foo, Goo, Hoo} ~ boohoo ~ {a, b, c}
 {Foo[a, b, c], Goo[a, b, c], Hoo[a, b, c]}
$\endgroup$
8
$\begingroup$
func={Foo,Goo,Hoo};
arg={a,b,c};

#@@arg&/@func
{Foo[a,b,c],Goo[a,b,c],Hoo[a,b,c]}

Let me know if you need an explanation. I figure a list of both functions and arguments would be the simplest method. Then I just made sure the Map over the functions would cause them to Apply to the arguments.

$\endgroup$
1
  • 1
    $\begingroup$ @MoneyOrientedProgrammer glad to hear it! Looks like kglr beat me again though haha D; $\endgroup$ Jun 11, 2020 at 3:47
3
$\begingroup$

Using ComapApply (new in 14.0)

ComapApply[{Foo, Goo, Hoo}] @ {a, b, c}

{Foo[a, b, c], Goo[a, b, c], Hoo[a, b, c]}

$\endgroup$
2
$\begingroup$

As of 2022 we have at our disposal the resource function called ThroughOperator that can do that. This is a development thanks to @Sjoerd Smit.

With

functions = {Foo, Goo, Hoo};
arguments = {a, b, c};

we do

ResourceFunction["ThroughOperator"][functions] @@ arguments

and we get:

{Foo[a, b, c], Goo[a, b, c], Hoo[a, b, c]}

$\endgroup$
0
$\begingroup$

Another way using Thread:

f = Activate[#1 @@@ #2 & @@@ Thread[{#1, Inactive[#2]}]] &;

f @@ {{Foo, Goo, Hoo}, {a, b, c}}

(*{Foo[a, b, c], Goo[a, b, c], Hoo[a, b, c]}*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.