({{, (RefLink[SubsetMap, paclet:ref/SubsetMap])[f,{(Subscript[e, 1]),(Subscript[e, 2]),…},{i,j,…}]
yields an expression in which the elements (Subscript[e, i]), (Subscript[e, j]), … in the list {(Subscript[e, 1]),(Subscript[e, 2]),…} are replaced with the corresponding elements of the list obtained by evaluating f[{(Subscript[e, i]),(Subscript[e, j]),…}].}, {, (RefLink[SubsetMap, paclet:ref/SubsetMap])[f,expr,{(Subscript[pos, 1]),(Subscript[pos, 2]),…}]
replaces elements of expr at positions (Subscript[pos, 1]), (Subscript[pos, 2]), ….}, {, (RefLink[SubsetMap, paclet:ref/SubsetMap])[f,{(Subscript[pos, 1]),(Subscript[pos, 2]),…}]
represents an operator form of (RefLink[SubsetMap, paclet:ref/SubsetMap]) that can be applied to an expression.}})

OpenersNotesSection(Spacer1)Details

In (RefLink[SubsetMap, paclet:ref/SubsetMap])[f,list,{(Subscript[i, 1]),…,(Subscript[i, n])}], the function f takes a length-n sublist of list and is expected to return another list of length n, whose elements will replace those of the original sublist.

OpenersPrimaryExamplesSection(Spacer1)Examples  (16)

OpenersExampleSection0(Spacer1)Basic Examples  (5)

Reverse elements at positions 2 and 4:

SubsetMap[Reverse,{x1,x2,x3,x4,x5,x6},{2,4}]

Extract, rotate and reinsert elements at positions 2, 4 and 5:

SubsetMap[RotateLeft,{x1,x2,x3,x4,x5,x6},{2,4,5}]

Extract, accumulate and reinsert elements at positions 2 to 5:

SubsetMap[Accumulate,{x1,x2,x3,x4,x5,x6},2;;5]

Reverse the elements of the diagonal of a matrix:

SubsetMap[Reverse,Array[(Subscript[x, ##])&,{3,3}],{{1,1},{2,2},{3,3}}]//MatrixForm

Accumulate the elements of the second column of a matrix:

SubsetMap[Accumulate,Array[(Subscript[x, ##])&,{3,3}],{All,2}]//MatrixForm

OpenersExampleSection1(Spacer1)Scope  (4)

Reverse the elements at even positions in a list:

SubsetMap[Reverse,Range[10],{2,4,6,8,10}]

Use equivalent notations for the position argument:

SubsetMap[Reverse,Range[10],{{2},{4},{6},{8},{10}}]

SubsetMap[Reverse,Range[10],2;;-1;;2]

Act on ragged arrays:

SubsetMap[Reverse,{{a,b},{c}},{{1,1},{2,1}}]

An alternative notation:

SubsetMap[Reverse,{{a,b},{c}},{All,1}]

Use (RefLink[SubsetMap, paclet:ref/SubsetMap]) as an operator form to show that these words are "even-letter palindromes":

Characters[{"rehabilitate","semiparasite"}]

SubsetMap[Reverse,{2,4,6,8,10,12}]/@%

Shift periodically the central elements of a list of colors:

NestList[SubsetMap[RotateRight,Range[5,10]],Hue/@Subdivide[0,0.8,12],12]//MatrixForm

OpenersExampleSection3(Spacer1)Applications  (1)

Implement a sorting network that randomly sorts pairs of elements until all elements are sorted:

randomSort[list_]:=With[{n=Length[list]},NestWhileList[SubsetMap[Sort,#,Sort@RandomInteger[{1,n},2]]&,list,Not@*OrderedQ]]

randomSort[Reverse@Range[4]]

ListLinePlot[Transpose[%]]

For longer lists, finding the last elements to reorder may take many steps:

Length[list=randomSort[Reverse@Range[20]]]

ListLinePlot[Transpose[list],ScalingFunctions->{"Log",None}]

OpenersExampleSection4(Spacer1)Properties & Relations  (4)

Use (RefLink[SubsetMap, paclet:ref/SubsetMap]) to shift the positions of a subset of elements in a list:

alphabet=Alphabet[]

SubsetMap[RotateRight,alphabet,{1,13,25}]

This can be also compactly expressed with (RefLink[Cycles, paclet:ref/Cycles]) notation and (RefLink[Permute, paclet:ref/Permute]):

%===Permute[alphabet,Cycles[{{1,13,25}}]]

(RefLink[SubsetMap, paclet:ref/SubsetMap])[f,expr,pos] is equivalent to (RefLink[MapAt, paclet:ref/MapAt])[f,expr,pos] for a listable function f:

SubsetMap[Sqrt,Range[10],{{2},{3},{5},{7}}]

MapAt[Sqrt,Range[10],{{2},{3},{5},{7}}]

(RefLink[SubsetMap, paclet:ref/SubsetMap])[f,expr,{}] returns expr:

SubsetMap[Accumulate,{a,b,c,d,e,f},{}]

(RefLink[SubsetMap, paclet:ref/SubsetMap])[f,expr,(RefLink[All, paclet:ref/All])] is equivalent to f[expr]:

SubsetMap[Accumulate,{a,b,c,d,e,f},All]

OpenersExampleSection5(Spacer1)Possible Issues  (2)

If the list of positions is not ordered, the result will inherit that order:

SubsetMap[Accumulate,{a,b,c},{3,2,1}]

In (RefLink[SubsetMap, paclet:ref/SubsetMap])[f,expr,{i,j,…}], the list {i,j,…} represents a list of positions, equivalent to {{i},{j},…}:

expr={x[1,a],x[2,b],x[3,c]};

SubsetMap[Accumulate,expr,{1,2}]

SubsetMap[Accumulate,expr,{{1},{2}}]

Other functions using position specifications, like (RefLink[Extract, paclet:ref/Extract]), interpret a list of integers as a single position:

Extract[expr,{1,2}]

Extract[expr,{{1},{2}}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[BlockMap, paclet:ref/BlockMap])  ▪  (RefLink[Map, paclet:ref/Map])  ▪  (RefLink[MapIndexed, paclet:ref/MapIndexed])  ▪  (RefLink[MapThread, paclet:ref/MapThread])  ▪  (RefLink[Extract, paclet:ref/Extract])  ▪  (RefLink[ReplacePart, paclet:ref/ReplacePart])  ▪  (RefLink[Insert, paclet:ref/Insert])  ▪  (RefLink[ArrayFilter, paclet:ref/ArrayFilter])  ▪  (RefLink[Construct, paclet:ref/Construct])  ▪  (RefLink[FoldPairList, paclet:ref/FoldPairList])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Applying Functions to Lists, paclet:guide/ApplyingFunctionsToLists])}, {▪(RefLinkPlain[Functional Programming, paclet:guide/FunctionalProgramming])}})}})