MapAt

MapAt[f,expr,n]

applies f to the element at position n in expr. If n is negative, the position is counted from the end.

MapAt[f,expr,{i,j,}]

applies f to the part of expr at position {i,j,}.

MapAt[f,expr,{{i1,j1,},{i2,j2,},}]

applies f to parts of expr at several positions.

MapAt[f,pos]

represents an operator form of MapAt that can be applied to an expression.

Details

  • MapAt[f,expr,{i,j,}] or MapAt[f,expr,{{i,j,}}] applies f to the part expr[[i,j,]].
  • MapAt[f,expr,{{i1,j1,},{i2,j2,},}] applies f to parts expr[[i1,j1,]], expr[[i2,j2,]], . »
  • The list of positions used by MapAt is in the same form as is returned by the function Position. »
  • MapAt works on Association objects, using the same specification for keys as in Part.
  • MapAt applies f repeatedly to a particular part if that part is mentioned more than once in the list of positions. »
  • MapAt[f,pos][expr] is equivalent to MapAt[f,expr,pos].

Examples

open allclose all

Basic Examples  (8)

Map f onto the part at position 2:

In[1]:=
Click for copyable input
Out[1]=

Map f onto multiple parts:

In[1]:=
Click for copyable input
Out[1]=

Map f onto a more deeply nested part:

In[1]:=
Click for copyable input
Out[1]=

Map f onto the second element of all top-level parts (the "second column"):

In[1]:=
Click for copyable input
Out[1]=

Map f onto an association:

In[1]:=
Click for copyable input
Out[1]=

Use Key to specify position:

In[1]:=
Click for copyable input
Out[1]=

For string keys, Key is not needed:

In[2]:=
Click for copyable input
Out[2]=

Use negative position in an association:

In[1]:=
Click for copyable input
Out[1]=

Use the operator form of MapAt:

In[1]:=
Click for copyable input
Out[1]=

Scope  (9)

Generalizations & Extensions  (4)

Applications  (4)

Properties & Relations  (2)

Possible Issues  (1)

See Also

Map  MapIndexed  ReplacePart  Delete  FlattenAt

Tutorials

Introduced in 1988
(1.0)
| Updated in 2014
(10.0)