MapIndexed is a very handy built-in function. Suppose that I have the following list, called list:
list = {10, 20, 30, 40};
I can use MapIndexed to map an arbitrary function f across list:
{f[10, {1}], f[20, {2}], f[30, {3}], f[40, {4}]}
where the second argument to f is the part specification of each element of the list.
But, now, what if I would like to use MapIndexed only at certain elements? Suppose, for example, that I want to apply MapIndexed to only the second and third elements of list, obtaining the following:
{10, f[20, {2}], f[30, {3}], 40}
Unfortunately, there is no built-in "MapAtIndexed", as far as I can tell. What is a simple way to accomplish this? Thanks for your time.
ReplacePartbased solutions seem to be ideal for this since they are not scanning through the list. – Kuba Jul 14 '13 at 12:13ReplacePartin theory, but it may be slower in practice than you might expect, especially for big lists. I suppose in theoryExtractalso does not scan the entire list. I would very much like it if there was a built in function that did what my myAtIndexed did, but for a given head inside theThread. Maybe I will elaborate on this later in a new post :). – Jacob Akkerboom Jul 14 '13 at 15:42