I would like to define an operator that takes some parameters as input and returns a function. Here is an example:
operator[indexLists_] := Function[weights,Table[Total[weights[[indexLists[[i]]]]], {i, Length[indexLists]}]];
example = {{1, 2, 3}, {5, 2, 1}, {1, 2}, {6, 7}};
op1 = operator[example]
which returns
Function[weights$, Table[Total[
weights$[[{{1, 2, 3}, {5, 2, 1}, {1, 2}, {6, 7}}[[i]]]]], {i, Length[{{1, 2, 3}, {5, 2, 1}, {1, 2}, {6, 7}}]}]]
what I would want is a partially evaluated version, i.e.
op2 = Function[weights, {Total[weights[[{1, 2, 3}]]], Total[weights[[{5, 2, 1}]]], Total[weights[[{1, 2}]]], Total[weights[[{6, 7}]]]}]
Both op1 and op2 return functions that perform the same thing, e.g. when called with "Range[8]" as argument they return {6, 8, 3, 13}.
This is a toy example. In my real example, the function returned by the operator performs some complex transformation of the input parameter "weights" that I want to pre-compute in order to be more efficient when evaluating the function many times. I could not figure out how to get around to HoldAll attribute of the pure function.