diff --git a/lib/linq.ts b/lib/linq.ts index 13db3d8..d03a911 100644 --- a/lib/linq.ts +++ b/lib/linq.ts @@ -190,7 +190,9 @@ class EnumerableImpl implements Enumerable, Iterable, IEnumerable { } let result: A = zero; for (let value of this) { - if (!result) result = Constant.getDefaultVal(typeof (value)); + if ([null, undefined].indexOf(result) > -1 || (isNaN(result as any) && !result)) + result = Constant.getDefaultVal(typeof (value)); + result = method(result, value); } return selector(result); diff --git a/test/immediate.ts b/test/immediate.ts index 42b23da..6269c72 100644 --- a/test/immediate.ts +++ b/test/immediate.ts @@ -33,7 +33,10 @@ describe('Immediate Execution -', function () { it('Aggregate() - Transform', function () { assert.equal(1814400, Linq.From(simpleArray).Aggregate(1, (a, b) => a * b, o => o / 2)); }); - + + it('Aggregate() - Default Value [String]', function () { + assert.equal("123", Linq.From([1, 2, 3]).Aggregate("", (c, n) => c.toString() + n.toString())); + }); // All