# Making functions with the output of a ReplaceAll

I'm trying to make a function from the variable "replace" of next code:

reactions = <|a -> αu #1/(ku + #1), b -> μu #1, c -> Du #1,
d -> αv #1/(kv + #1), e -> αi #2 #1/(ki + #1),
f -> μv #2, g -> Dv #2|>;

replace = {a, c, d} /. reactions


I want to Apply the output of "replace" to a list of numbers:

replace & @@ {1, 2}


But this returns the next output without any solution:

{(33.25 #1)/(450 + #1), 0.035 #1, 0.4 #1}


Why this doesn't work?

If a try to become "replace" in a Function, it also doesn't work.

Make each element of replace a function by wrapping it with Function.

functions = Function /@ replace


{(αu #1)/(ku + #1) &, Du #1 &, (αv #1)/(kv + #1) &}

Use functions with Through to apply all functions to the same argument:

Through[functions@1]


{αu/(1 + ku), Du, αv/(1 + kv)}

Use Map to apply this function to a list of arguments:

Through[functions@#] & /@ {1, 2}


{{αu/(1 + ku), Du, αv/(1 + kv)},
{(2 αu)/(2 + ku), 2 Du, (2 αv)/(2 + kv)}}

Alternatively, map Function on reactions before you create replace:

reactions2 = Function /@ reactions;
replace2 = {a, c, d} /. reactions2;
Through[replace2@#] & /@ {1, 2}


same result

fn = Function @@ {replace};

fn[2]

{(2 αu)/(2 + ku), 2 Du, (2 αv)/(2 + kv)}

fn /@ {1, 2}

{{αu/(1 + ku), Du, αv/(1 + kv)}, {(2 αu)/(2 + ku), 2 Du, (2 αv)/(2 + kv)}}

fn @ {1, 2}

{{αu/(1 + ku), (2 αu)/(2 + ku)}, {Du, 2 Du}, {αv/(1 + kv), (2 αv)/(2 + kv)}}