Is there a more elegant way to do the following? (The code should be f
-less and replacement-less)
expr = f[a, b, c];
Head@# /@ List @@ # &@expr
{f[a], f[b], f[c]}
If it were a list of arguments then elegant solution would be:
expr = f[{a, b, c}];
Thread[expr]
{f[a], f[b], f[c]}
But that is not the case. My expression is f[a, b, c]
not f[{a, b, c}]
.
The shortest code I found was f /@ List @@ expr
but this contains f
which I want to be avoided.
Replace[head_[args___] :> head /@ {args}] @ expr
is about as elegant as I think it'll get. It's not exactly as standard transformation you encounter regularly. $\endgroup$