Basic Examples (3)
Apply f to the first element of a list and g to the second:
Apply func to the value of a Key in an Association:
Use the operator form of MapAtPart:
Scope (7)
Symbolic Part Specifications (3)
Apply f to the First element of a list and g to the Rest:
Apply f to Most of the list and g to the Last element:
Apply f to the First element of the list and g to the Span of elements from position 3 onward:
Use the shorthand (;;) syntax for Span:
Properties and Relations (8)
MapAtPart is implemented with Fold and MapAt; use FoldList to see intermediate steps:
MapAtPart[i→f,expr] is equivalent to MapAt[f,expr,i]:
Use multiple positions:
MapAtPart[i→f,expr] is equivalent to SubsetMap[Map[f],expr,i]:
Use multiple positions:
MapAtPart[f,expr] is equivalent to Apply[f,expr]:
A position specification of All is equivalent to MapAt[f,expr,All] and also equivalent to Map[f,expr]:
If the right-hand side of a replacement wraps the bound expression, then ReplaceAt is also equivalent to the above when the part is All:
ReplacePart has access to indices but not elements:
Conversely, MapAtPart has access to the element values, but not their part specifications:
To have access to both indices and element, one needs to use intermediate assignment:
MapAtPart statements can be longer than ReplaceAll statements:
The resource function SetComplementMap uses explicit positions for the first function:
MapAtPart uses explicit positions for all functions:
Possible Issues (7)
Functions are applied to individual elements not sublists:
A Function specified with shorthand (#&) should be wrapped in parentheses:
A list of integers is considered a part path:
If each integer is meant as an index on the same level then either wrap them in a list, or use Span:
When specifying an operator form, remember to wrap the function specification in a list. Notice below that All→g is applied to the second argument 2→f:
Wrap the specification in List to get an operator form:
If a preceding function changes the expression's structure, then subsequent functions won't work as expected (especially if the positions in the expression no longer exist):
Beware of symbol precedence. For example, an inner Style has precedence over an outer Style, so parts 3 and 4 below are Red instead of Green:
Framed, however, shows all styles:
Expressions with a Depth <= 1 will return a Failure: