6
$\begingroup$
MapAt[f, {{a, b, {c, d}}, {d, {e, g, {c, d}}}}, 1]

How to operate to get such a result:

{{f[a], f[b], {f[c], f[d]}}, {f[d], {f[e], f[g], {f[c], f[d]}}}}
$\endgroup$
10
$\begingroup$

One can also temporarily apply a Listable function with

Function[x, f[x], Listable][list]

Listability works differently than mapping to level {-1} when the elements of the list have parts:

Function[x, f[x], Listable][{b, {e, g, {c, a + Exp[d]}}}]
(*  {f[b], {f[e], f[g], {f[c], f[a + E^d]}}}  *)

Map[f, {b, {e, g, {c, a + Exp[d]}}}, {-1}]
(*  {f[b], {f[e], f[g], {f[c], f[a] + f[E]^f[d]}}}  *)
|improve this answer|||||
$\endgroup$
8
$\begingroup$

you can also give the attribute Listable to your function

SetAttributes[f, Listable]

and then simply write

f@{{a, b, {c, d}}, {d, {e, g, {c, d}}}}
|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.