4
$\begingroup$

Given a list of functions

{f1, f2, f3, ...}

and list of inputs

{1, 2, 3, ...}

I wish to produce the list

{f1[1], f2[2], f3[3], ...}

This is the list where each function in the first list is applied to the input at the corresponding index. How can I do this concisely?

$\endgroup$
6
$\begingroup$
funcs = {f1, f2, f3};
lst = {1, 2, 3};

MapThread[# @ #2 &, {funcs, lst}]

{f1[1], f2[2], f3[3]}

Also

MapThread[Construct, {funcs, lst}]

Inner[Construct, funcs, lst, List]

MapThread[Compose, {funcs, lst}]

Inner[Compose, funcs, lst, List]

same result

$\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.