MapAt

WMA link


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, pos]

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

Map function f to the second element of an simple flat list:

Above, we specified a simple integer value 2. In general, the expression can be an arbitrary vector.

Using MapAt with Function[0], we can zero a value or values in a vector:

When the dimension of the replacement expression is less than the vector, that element's dimension changes:

So now compare what happen when using {{2}, {1}} instead of {2, 1} above:

Map f onto the last element of a list:

Same as above, but use the operator form of MapAt:

Map f onto at the second position of an association:

Same as above, but select the second-from-the-end position:

Map
MapIndexed