Is there a simple way to apply a function to the RHS of a substitution?

sol = {
   {f[a1] -> SomeComplicatedFunction[x, a1]},
   {f[a2] -> SomeComplicatedFunction[x, a2]},
   {f[a3] -> SomeComplicatedFunction[x, a3]}};

sol2 = sol /. Rule[lhs_, rhs_] :> Rule[lhs, myFunction[rhs]]

(* {{f[a1] -> myFunction[SomeComplicatedFunction[x, a1]]}, {f[a2] -> 
   myFunction[SomeComplicatedFunction[x, a2]]}, {f[a3] -> 
   myFunction[SomeComplicatedFunction[x, a3]]}} *)

Additional alternatives:

You can use MapAt to map myFunction at positions {All, -1, -1}:

sol3 = MapAt[myFunction, sol, {All, -1, -1}]

{{f[a1] -> myFunction[SomeComplicatedFunction[x, a1]]},
{f[a2] -> myFunction[SomeComplicatedFunction[x, a2]]},
{f[a3] -> myFunction[SomeComplicatedFunction[x, a3]]}}

You can assign new values at desired positions using Part assignment:

sol4 = sol;
sol4[[All, -1, -1]] = myFunction /@ sol4[[All, -1, -1]];
sol4

same result

Tags:

Rule