5
$\begingroup$

Assume that you have two lists of the same size where
1st contains functions for ex. {u,i,o,p}
2nd contains numbers for ex. {1,2,3,4}.
Create list such that each function is matched to each element:
{u[1], i[2], o[3], p[4]}

$\endgroup$

marked as duplicate by Mr.Wizard functions Jul 1 '17 at 5:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ Something like MapThread[#1[#2] &, {{u, i, o, p}, {1, 2, 3, 4}}] will work $\endgroup$ – Jason B. Jun 29 '17 at 18:52
6
$\begingroup$
Compose @@@ Transpose[{{u, i, o, p}, {1, 2, 3, 4}}]
Inner[Compose, {u, i, o, p}, {1, 2, 3, 4}, List]
MapThread[Compose, {{u, i, o, p}, {1, 2, 3, 4}}]
Module[{t = Thread[{##}]}, t[[All, 0]] = #@#2 &; t] &[{u, i, o, p}, {1, 2, 3, 4}]

all give

{u[1], i[2], o[3], p[4]}

You can use #@#2& in place of Compose above to get the same results.

Also, for fun,

☺ = # @ #2 & @@@ ({##}) &;

Mathematica graphics

☺[{u, i, o, p}, {1, 2, 3, 4}]

{u[1], i[2], o[3], p[4]}

$\endgroup$
  • $\begingroup$ Is # @ #2 & @@@ ({##}T) &; the same as #1[#2] & @@@ Transpose[##]&? $\endgroup$ – I should change my Username Jun 29 '17 at 21:17
  • $\begingroup$ @IshouldchangemyUsername, almost. You need to change Transpose[##] to Transpose[{##}]. $\endgroup$ – kglr Jun 29 '17 at 21:19
3
$\begingroup$

This will also work:
Transpose[{{u, i, o, p}, {1, 2, 3, 4}}] /. {x_Symbol, y_Integer} -> x[y]

$\endgroup$

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