Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
A version of MapAt that evaluates even within held expressions
ResourceFunction["MapAtEvaluate"][f,expr,pos] maps function f at position pos of the expression expr with evaluation. | |
ResourceFunction["MapAtEvaluate"][f,expr,pos,patt] specifies a pattern to delete after evaluation. | |
ResourceFunction["MapAtEvaluate"][f,pos] represents an operator form that can be applied to an expression. |
Map a function at a single position of an expression and evaluate in-place:
In[1]:= |
Out[1]= |
Map at multiple positions:
In[2]:= |
Out[2]= |
Use All and Span to map over multiple subexpression parts:
In[3]:= |
Out[3]= |
In[4]:= |
Out[4]= |
In[5]:= |
Out[5]= |
Prevent evaluation of the function output with Unevaluated:
In[6]:= |
Out[6]= |
The Unevaluated is not present in the result:
In[7]:= |
Out[7]= |
Specify a different subexpression to delete after evaluation:
In[8]:= |
Out[8]= |
In[9]:= |
Out[9]= |
Prevent evaluation of subexpressions using a function with held arguments:
In[10]:= |
Out[10]= |
Evaluate subexpressions:
In[11]:= |
Out[11]= |
In[12]:= |
Out[12]= |
Map at a held Sequence:
In[13]:= |
Out[13]= |
In[14]:= |
Out[14]= |
Map at a held Evaluate:
In[15]:= |
Out[15]= |
In[16]:= |
Out[16]= |
Unevaluated function evaluates at each position:
In[17]:= |
Out[17]= |
In[18]:= |
Out[18]= |
MapAt does not evaluate the function it is mapping inside held arguments:
In[19]:= |
Out[19]= |
MapAtEvaluate does:
In[20]:= |
Out[20]= |
MapAt fails if any position is invalid:
In[21]:= |
Out[21]= |
MapAtEvaluate silently ignores invalid positions:
In[22]:= |
Out[22]= |
The resource function ReplaceAt with a _/;True condition can achieve the same results:
In[23]:= |
Out[23]= |
In[24]:= |
Out[24]= |
With MapAtEvaluate, one can control which subexpressions not to evaluate without producing an additional wrapper:
In[25]:= |
Out[25]= |
In[26]:= |
Out[26]= |
The resource function MapCases with the option "EvaluateCases"→True has similar behavior to MapAtEvaluate, except that it takes patterns instead of positions:
In[27]:= |
Out[27]= |
In[28]:= |
Out[28]= |
This work is licensed under a Creative Commons Attribution 4.0 International License