Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Map functions over data, stopping when an error is generated
ResourceFunction["ConfirmedMapping"][mapper, f, data, …] is a modified version of a mapping operation such as Map that short-circuits when a failure is generated. | |
ResourceFunction["ConfirmedMapping"][mapper, f→test, data, …] uses a test function test to check if values returned by f should be considered an error. | |
ResourceFunction["ConfirmedMapping"][mapper] represents a mapping operation with error checking. | |
ResourceFunction["ConfirmedMapping"][mapper[f]] represents the operator mapper[f] with added error checking. | |
ResourceFunction["ConfirmedMapping"][mapper][f] is the same as ResourceFunction["ConfirmedMapping"][mapper[f]]. |
Map OpenRead over a list of files, aborting when it fails:
In[1]:= | ![]() |
Out[1]= | ![]() |
Use a custom test function to determine whether there was a failure:
In[2]:= | ![]() |
Out[2]= | ![]() |
Define a function that returns a failure if its argument is not numeric:
In[3]:= | ![]() |
Map the function over numbers:
In[4]:= | ![]() |
Out[4]= | ![]() |
If f returns a Failure for any element, a failure will be thrown to the top level:
In[5]:= | ![]() |
Out[5]= | ![]() |
Map at a deeper level:
In[6]:= | ![]() |
Out[6]= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
Use AssociationMap as the mapper instead:
In[8]:= | ![]() |
Out[8]= | ![]() |
In[9]:= | ![]() |
Out[9]= | ![]() |
Use MapAt:
In[10]:= | ![]() |
Out[10]= | ![]() |
In[11]:= | ![]() |
Out[11]= | ![]() |
Use Confirm to throw the returned Failure up to the nearest Enclose:
In[12]:= | ![]() |
Out[12]= | ![]() |
Specify a test for value returned by the function:
In[13]:= | ![]() |
Out[13]= | ![]() |
In[14]:= | ![]() |
Out[14]= | ![]() |
In[15]:= | ![]() |
Out[15]= | ![]() |
In[16]:= | ![]() |
Out[16]= | ![]() |
Use the operator form to define a modified version of Map:
In[17]:= | ![]() |
In[18]:= | ![]() |
Out[18]= | ![]() |
In[19]:= | ![]() |
Out[19]= | ![]() |
The new function supports operator forms as well:
In[20]:= | ![]() |
Out[20]= | ![]() |
In[21]:= | ![]() |
Out[21]= | ![]() |
Alternatively, define the mapping of f as an operator directly:
In[22]:= | ![]() |
In[23]:= | ![]() |
Out[23]= | ![]() |
In[24]:= | ![]() |
Out[24]= | ![]() |
Operator forms of MapAt:
In[25]:= | ![]() |
In[26]:= | ![]() |
Out[26]= | ![]() |
In[27]:= | ![]() |
Out[27]= | ![]() |
In[28]:= | ![]() |
Out[28]= | ![]() |
In[29]:= | ![]() |
Out[29]= | ![]() |
In[30]:= | ![]() |
Out[30]= | ![]() |
In[31]:= | ![]() |
Out[31]= | ![]() |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License