Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
An operator that applies multiple functions to one set of arguments
ResourceFunction["ThroughOperator"][{f1,f2,…}][arg1,arg2,…] returns {f1[arg1,arg2,…],f2[arg1,arg2,…],…}. | |
ResourceFunction["ThroughOperator"][{f1,f2,…}, h][args,…] returns h[f1[args,…],f2[args,…],…]. | |
ResourceFunction["ThroughOperator"][<|key1→f1,key2→f2,…|>][args,…] returns <|key1→f1[args,…],key2→f2[args,…],…|>. |
Apply a list of functions to some arguments:
In[1]:= | ![]() |
Out[1]= | ![]() |
ThroughOperator can be mapped easily:
In[2]:= | ![]() |
Out[2]= | ![]() |
In[3]:= | ![]() |
Out[3]= | ![]() |
ThroughOperator works with other heads as well:
In[4]:= | ![]() |
Out[4]= | ![]() |
Define an operator that generates an Association with function values:
In[5]:= | ![]() |
Out[5]= | ![]() |
Compute a number of Booleans for a number; use And to test if they are all True:
In[6]:= | ![]() |
Out[6]= | ![]() |
This can be achieved with the two-argument form as well:
In[7]:= | ![]() |
Out[7]= | ![]() |
Note that only the necessary functions are evaluated:
In[8]:= | ![]() |
Out[8]= | ![]() |
In[9]:= | ![]() |
Out[9]= | ![]() |
The two-argument form of ThroughOperator is convenient for functions that would evaluate prematurely in the one-argument form:
In[10]:= | ![]() |
Out[12]= | ![]() |
In[13]:= | ![]() |
Out[13]= | ![]() |
Other functions will work correctly in the one-argument form but will issue messages:
In[14]:= | ![]() |
Out[14]= | ![]() |
These messages can be avoided with the two-argument form:
In[15]:= | ![]() |
Out[15]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License