MapIndexed¶
Applies a function to each element and its index.
On an association the index is {Key[key]}.
A negative level names the parts of a given depth, counted from the leaves and
measured for each part on its own. -2 reaches every part whose own depth is
at least two, so the nested {4, 5} is mapped but the atoms are not:
{-1} on its own reaches only the atoms:
$ wo 'MapIndexed[f, {{1, 2}, {3, {4, 5}}}, {-1}]'
{{f[1, {1, 1}], f[2, {1, 2}]}, {f[3, {2, 1}], {f[4, {2, 2, 1}], f[5, {2, 2, 2}]}}}
Infinity and All reach everything: