Compound aggregates

Topics: Help
Jan 23, 2014 at 4:39 AM
Edited Jan 23, 2014 at 4:45 AM
Hello all,

I'm wondering if you can help me. I'm considering using NCalc for an application - it looks to be a very good fit. However, I'm trying to work out if it's capable of something.

I'd like to be able to evaluate this:

SUM(SomeList * SomeOtherList)

or this:

SUM((SomeList * 0.2) * (SomeOtherList - 1))

As examples. The expected behaviour would be that (assuming the lists are the same length) it would evaluate the inner expression once per list point, then pass the results as an array to the SUM() function.

I'm guessing that in order to support that behaviour, it would have to treat the expression inside the SUM() function differently and iteratively evaluate it, once per data point in the lists).

Anyone know if it supports this directly? Or if not, if it has appropriate extension points to allow the evaulation behaviour inside a function (or a custom function if necessary) to be altered?

Essentially, as you might have guessed, I'm trying to produce behaviour similar to Excel's array formula functionality.

Any insight would be much appreciated :)

James
Jan 23, 2014 at 5:12 AM
So after having a play, the answer would appear to be yes. It's incredibly flexible.

The approach I've taken as a proof of concept is to register a custom evaluation function, then switch the "IterateParameters" argument on for the function expression inside the SUM(). It works.

There's a degree of inconsistency around whether a result is returned as a simple value or as an IEnumerable. Instead of the IterateParameters option, I wonder if it would be more intuitive to have an EvaluateIterative() method with results which were strongly typed to IEnumerable<object>?