This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / Built-in Functions / Programming / Functional Programming  /
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 , , , ... , , , ... , ... ] applies f to parts of expr at several positions.
  • Example: MapAt[f, a, b, c , 2].
  • MapAt[f, a, b, c, d , 1 , 4 ].
  • MapAt[ f , expr , i , j , ... ] or MapAt[ f , expr , i , j , ... ] applies f to the part expr [[ i , j , ... ]].
  • MapAt[ f , expr , , , ... , , , ... , ... ] applies f to parts expr [[ , , ... ]], expr [[ , , ... ]], ... .
  • The list of positions used by MapAt is in the same form as is returned by the function Position.
  • MapAt applies f repeatedly to a particular part if that part is mentioned more than once in the list of positions.
  • Example: MapAt[f, a, b, c , 1 , 3 , 1 ].
  • See the Mathematica book: Section 2.2.4.
  • See also: ReplacePart, Delete, FlattenAt.

    Further Examples

    This specifies that f is mapped across the list at position 2 only.

    In[1]:=

    Out[1]=

    Here, f is mapped on the first position of the second element.

    In[2]:=

    Out[2]=

    To avoid ambiguity, you must put each part specification in a list, even when it involves only one index.

    In[3]:=

    Out[3]=