Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Apply a function to elements at certain positions and another function to the rest of the elements
ResourceFunction["SetComplementMap"][f1,f2,list,pos] applies f1 to elements in list at positions pos and applies f2 to the rest of the elements. |
Color numbers at particular positions red and color the rest blue:
| In[1]:= | ![]() |
| Out[1]= |
| In[2]:= |
| Out[2]= |
Rotate strings in a list and style them red while coloring the rest of the elements blue:
| In[3]:= | ![]() |
| Out[4]= |
| In[5]:= |
| Out[5]= |
If only one function is given, the second function defaults to Identity:
| In[6]:= |
| Out[6]= |
| In[7]:= |
| Out[7]= |
If no functions are given, the list is returned:
| In[8]:= |
| Out[8]= |
| In[9]:= |
| Out[9]= |
The second function can change the list's shape:
| In[10]:= |
| In[11]:= |
| Out[11]= |
If a position is out of scope, a Failure is returned:
| In[12]:= |
| In[13]:= |
| Out[13]= |
| In[14]:= |
| Out[14]= | ![]() |
If the first function changes the list-length, then one or more end positions no longer exist, producing a Failure when one or the other function attempts to evaluate at those positions.
| In[15]:= |
| In[16]:= |
| Out[16]= | ![]() |
Changes of structure due to f2 do not have this issue:
| In[17]:= |
| Out[17]= |
| In[18]:= |
| Out[18]= |
Wolfram Language 12.3 (May 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License