2
$\begingroup$

Is there a way to apply an array of functions or others to a single entity?

An example would be:

In[1]:= {1, 3, 8, 8.5, 9} //{Min, Max}
Out[1]:= {1, 9}

or

In[2]:= 12.5 //{f, g, h}
Out[2]:= {f[12.5], g[12.5], h[12.5]}

This isn't function mapping, because it's applying to a single element, not over elements of a list (but rather treating a list as its own element)

$\endgroup$
  • $\begingroup$ I found and duplicate Question so marked this accordingly. Also related: (83720) $\endgroup$ – Mr.Wizard Nov 26 '16 at 14:21
2
$\begingroup$

This operation is performed by Through:

12.5 // {f, g, h} // Through
{f[12.5], g[12.5], h[12.5]}

Other methods:

#[12.5] & /@ {f, g, h}

Table[fn[12.5], {fn, {f, g, h}}]

Cases[{f, g, h}, fn_ :> fn[12.5]]

Each of these occasionally has a good application so it can be useful to know them.

$\endgroup$
  • $\begingroup$ Very clean. Thank you! $\endgroup$ – Peaser Nov 19 '16 at 8:28

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