Skip to content

Commit

Permalink
Fixes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
ENikS committed Nov 4, 2016
1 parent 4f82899 commit 1a5ce14
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function* ChunkBy<T, K, E, V>(target: Iterable<T>,
box.push(elementSelector(value));
}

if (key && box) {
if (box && 0 < box.length) {
yield resultSelector(key, box);
}
}
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@
"url": "https://github.com/ENikS/Linq.git"
},
"devDependencies": {
"browserify": "^13.0.1",
"chai": "^3.2.0",
"browserify": "^13.1.1",
"chai": "^3.5.0",
"jsmin": "^1.0.1",
"mocha": "^3.0.2",
"typescript": "^2.0.3"
"latest": "^0.2.0",
"mocha": "^3.1.2",
"typescript": "^2.0.7"
},
"scripts": {
"build:ts": "tsc",
Expand Down
25 changes: 23 additions & 2 deletions test/deferred.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ describe('Deferred Execution -', function () {

it('ChunkBy() - Index', function () {

let iterable = Linq(phrase).ChunkBy((o, i) => Math.max(3, i),
o => o.value);
let iterable = Linq(phrase).ChunkBy((o, i) => Math.max(3, i),
o => o.value);
var iterator = iterable[Symbol.iterator]()
var arr = iterator.next().value as Array<string>;
assert.equal(arr.length, 4);
Expand All @@ -82,6 +82,27 @@ describe('Deferred Execution -', function () {
});


it('ChunkBy() - Zero', function () {

let iterable = Linq([{ key: 0, value: "0" },
{ key: 0, value: "1" },
{ key: 0, value: "2" },
{ key: 0, value: "3" },
{ key: 0, value: "4" },
{ key: 0, value: "5" },
{ key: 0, value: "6" },
{ key: 0, value: "7" },
{ key: 0, value: "!" }])
.ChunkBy(k => k.key, o => o.value);

debugger;
var iterator = iterable[Symbol.iterator]()
var arr = iterator.next().value as Array<string>;
assert.equal(arr.length, 9);
assert.isTrue(iterator.next().done);
});


// Concat

it('Concat()', function () {
Expand Down

0 comments on commit 1a5ce14

Please sign in to comment.