3

Suppose that I have

f[a_, b_, x_] := ...

I'd like to create a list of n pure functions

{f[1, 4, #]&, f[2, 5, #]&, f[3, 6, #]&, ...}

from two lists of length n like

as = {1, 2, 3, ...}
bs = {4, 5, 6, ...}

What can I do?

Given g[a_, b_] = ..., I know that to get {g[1, 4], g[2, 5], g[3, 6], ...} is to use MapThread[g, {as, bs}], but I don't know how to extend this idea to solve the above problem.

Taiki
  • 5,259
  • 26
  • 34

2 Answers2

2

You're very close to the solution. You already have

as = {1, 2, 3}
bs = {4, 5, 6}

MapThread[g, {as, bs}]

(* ==> {g[1, 4], g[2, 5], g[3, 6]} *)

Now all you need is

g[a_, b_][x_] := f[a, b, x]

Or alternatively write Function[{a, b}, f[a, b, #] &] in place of g in MapThread.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
2

Also:

Transpose[{as, bs}] /. {a_, b_} :> (f[a, b, #] &)
(* {f[1, 4, #1] &, f[2, 5, #1] &, f[3, 6, #1] &} *)
kglr
  • 394,356
  • 18
  • 477
  • 896