The gist of this question is to find a function that takes a list of functions and a list of arguments and wraps each argument with the corresponding function e.g. someFunction[{f1, f2, f3}, {arg1, arg2, arg3}]
should evaluate to {f1[arg1], f2[arg2], f3[arg3]]}
. Of the given answers I find none that is really readable and I though that the undeservedly seldom used Thread
might offer a better solution. What it does is that it pairs arguments from one list with arguments from a second list
Thread[someHead[{a, b, c}, {x, y, z}]]
(* {someHead[a, x], someHead[b, y], someHead[c, z]} *)
The snag here is someHead
unfortunately. I couldn't find a nice function someHead[f, arg]
that evaluates to f[arg]
i.e. applies f
as a Head
to arg
and I started wondering why this is.
This brings me to my question:
Is there a function/expression similar to Apply
, Map
, Composition
and friends for basic function application, i.e. wrapping an expression with a Head? Compare for instance
Thread[Composition[{a, b, c}, {x, y, z}]]
(* {a@*x, b@*y, c@*z} *)
This leads to a philosophical question: In functional programming language, should there be a function for applying a function?
Thread[Inactivate[(#1@#2 &)][{a, b, c}, {x, y, z}]] // Activate
by the way. For some reasonThread[(#1@#2 &)[{a, b, c}, {x, y, z}]]
does not work. $\endgroup$