c# - Creating an n-nary expression -
i have sequence of n system.linq.expressions.expression want convert n-nary expression connects expressions 1 using operator n-1 times.
so collection of 4 expressions {e1, e2, e3, e4} , operator and get: e1 , e2 , e3 , e4.
since operator same, can create expression chaining n-1 binaryexpressions
expression result = (((e1 , e2) , e3) , e4); but i'm thinking there may easier way of doing this. like
expression.nnary(expressiontype operator, ienumerable<expression> expressions) is there implemented or have binaryexpressions ?
what you're describing reduce function, known aggregate in linq. reduces sequence of values single value, this:
int[] numbers = { 1, 2, 3, 4 }; int sum = numbers.aggregate((acc, current) => acc + current, 0); // 10 how you're combining acc , current you.
Comments
Post a Comment