3
$\begingroup$

I have a function f[m,n] and a list of arguments args = {{m1,n1},{m2,n2},{m3,n3},{m4,n4}, ...} that I want to apply to it. I tried f/@args, but this yields {f[{m1,n1}], ...}. Is there a more elegant solution than defining the function as f[{m,n}]?

$\endgroup$
5
$\begingroup$
args = {{m1, n1}, {m2, n2}, {m3, n3}, {m4, n4}};

f @@@ args

{f[m1, n1], f[m2, n2], f[m3, n3], f[m4, n4]}

Apply[f, args, {1}]

{f[m1, n1], f[m2, n2], f[m3, n3], f[m4, n4]}

f @@ # & /@ args

{f[m1, n1], f[m2, n2], f[m3, n3], f[m4, n4]}

f[Sequence @@ #] & /@ args

{f[m1, n1], f[m2, n2], f[m3, n3], f[m4, n4]}

% == %% == %%% == %%%%

True

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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