3

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)

Peaser
  • 133
  • 2

1 Answers1

4

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.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371