Is sum supposed to fail when empty?

Apr 4, 2010 at 2:43 PM
Edited Apr 4, 2010 at 2:43 PM

Hi,

Given the following code:

var foo = new jsinq.Enumerable([ 42 ]);
var computedSum = foo
	.where(function (x) { return x > 100; })
	.sum();

I get  'InvalidOperationException: Operation is not valid due to the current state of the object.' and I wonder if this is a bug or if it's designed to behave like this?

My current workaround is to only compute the sum when there are items in the list and it feels ugly.

var foo = new jsinq.Enumerable([ 42 ]);
var computedSum = 0;
var result = foo
	.where(function(x) { return x > 100; });
if (result.count() > 0)
	computedSum = result.sum();

Thanks

Coordinator
Apr 4, 2010 at 5:31 PM

Hi and thanks for reporting this issue,

you're absolutely right that sum() should not throw when invoked on an empty enumerable (unlike average, min and max). 

Would you please download the new 1.0.0.1 release and let me know if this works for you?

Thanks and cheers,

Kai

Apr 6, 2010 at 11:41 AM

Hi,

The new release works great!

Thanks for the quick fix.