Use With
instead of Module
?
ClearAll[a, b, c, d, pick, ex, co]
ClearAll[a, b, c, d, pick, ex, co]
ExpandPick[exp_] := With[{
p = FirstPosition[exp, _pick]
}, With[{
x = First@Extract[exp, p],
y = Last@Extract[exp, p]
},
ReplacePart[exp, p :> ex[Function[co, {co[x], co[y]}]]]]]