Skip to content
This repository was archived by the owner on Jul 4, 2019. It is now read-only.

Commit ba3285b

Browse files
committed
fix Lag
1 parent d0d7215 commit ba3285b

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "linqable.ts",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"description": "LINQ implementation library for TypeScript",
55
"main": "./build/Extensions.js",
66
"author": "Yuuki Wesp",

src/AdvancedLinqable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class AdvancedLinqable<T> extends BaseLinqable<T> {
116116
let generator = function* ()
117117
{
118118
var i = offset;
119-
var lagQueue = new Array<T>(offset);
119+
var lagQueue = new Array<T>();
120120
var hasMore = true;
121121
let iter = that.GetIterator();
122122
while (i-- > 0 && (hasMore = iter.moveNext()))

test/Advanced.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ test("Consume", (t) => {
2929

3030

3131
test("Lag", (t) => {
32-
t.plan(2);
32+
t.plan(4);
3333
let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
3434
t.throws(() => {
3535
arr.Lag(-10, 0,(val, lagVal) => val);
3636
}, "offset <= 0");
3737
let result = arr.Lag(2, 0, (a, b) => { return { A: a, B: b}; })
3838
t.deepEqual(10, result.Count());
39+
console.log(JSON.stringify(result))
40+
t.true(result.slice(2).All(x => x.B == (x.A - 2)));
41+
t.true(result.Take(2).All(x => (x.A - x.B) == x.A));
3942
});
4043

4144
test("Exclude", (t) => {
@@ -66,3 +69,12 @@ test("Flatten", (t)=>{
6669
test("Pairwise", (t) => {
6770
t.deepEqual([123, 456, 789].Pairwise(function(x,y) {return {x, y}}), [{x:123,y:456},{x:456,y:789}]);
6871
})
72+
73+
test("Pipe", (t) => {
74+
t.plan(3);
75+
let arr = [{x: 12}, {x: 12}, {x: 12}];
76+
arr.Pipe(x => {x.x++;})
77+
t.deepEqual(arr[0].x, 13);
78+
t.deepEqual(arr[1].x, 13);
79+
t.deepEqual(arr[2].x, 13);
80+
})

0 commit comments

Comments
 (0)