Consider a pair of functions f1
and f2
, and a vector {x,y}
. I can get easily {f1[x],f2[y]}
by doing MapThread[#1@#2 &,{f1,f2},{x,y}]
.
Now imagine that I have a function F
defined as
F := {f1[#],f2[#]} &
Of course I cannot use the same procedure to get the same result, because now F
is not a list of functions (as it was {f1,f2}
), but a function itself that returns a list.
One way to get this result (and that admits generalization to longer lists) is
Diagonal[F/@{x,y}]
With this solution we build a whole matrix of elements of F
acting on elements of the arguments list and we select the ones that we want.
I was wondering if there is a solution kind of like MapThread
that gives the direct result, making act one-to-one the $n$-th element of the function with the $n$-th argument.
:=
forF
is strange here. Are you aware of the distinction between Set and SetDelayed? $\endgroup$f1
andf2
are supposed to stand for concrete functions in this case (for example,F := {D[#,x],D[#,y]}&
). $\endgroup$:=
is never needed if the right-hand side only has aFunction
(i.e....&
). That's becauseFunction
already holds its arguments. It doesn't hurt to use:=
but the result will be exactly the same as it would have been with=
. $\endgroup$=
for OwnValue assignments unless there is a special reason not to. If I see:=
, I automatically look for a special reason. This is of course just my way of working. I can't think of a technical reason why:=
is bad here. $\endgroup$