diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7dff2a3 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: Test Lint Fmt + +on: + pull_request: + branches: + - main + +jobs: + deno-ci: + runs-on: ubuntu-latest + + steps: + # Checkout the code + - name: Checkout code + uses: actions/checkout@v4 + + # Set up Deno + - name: Set up Deno + uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + + # Test the project + - name: Run tests + run: deno test + + # Format check + - name: Check formatting + run: deno fmt --check + + # Lint check + - name: Lint code + run: deno lint diff --git a/.gitignore b/.gitignore index 0a7516b..dbd9187 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules *.js yarn-error.log docs +coverage diff --git a/deno.json b/deno.json index b06fe18..184f1b4 100644 --- a/deno.json +++ b/deno.json @@ -8,6 +8,9 @@ "dev": "deno test --watch src/mod.ts", "doc": "deno doc --html --name=\"lazy iterators\" ./src/mod.ts" }, + "publish": { + "include": ["LICENSE", "README.md", "src/**/*.ts"] + }, "imports": { "@std/expect": "jsr:@std/expect@^1.0.9", "@std/testing": "jsr:@std/testing@^1.0.6" diff --git a/src/mod.ts b/src/mod.ts index 9407085..2b74965 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -296,15 +296,15 @@ class SizedIter extends Iter implements SizedLazyIterator { return this.__lastElement; } - let v = undefined; + let value = undefined; while (true) { - const n = this.iterator!.next(); - __dir({ n, v }); - if (n.done) { - this.__lastElement = v; - return v; + const next = this.iterator!.next(); + __dir({ next, value }); + if (next.done) { + this.__lastElement = value; + return value; } - v = n.value; + value = next.value; } } @@ -314,14 +314,14 @@ class SizedIter extends Iter implements SizedLazyIterator { override intoArray(): T[] { const all = new Array(this.size); - let nxt: IteratorResult | undefined; + let next: IteratorResult | undefined; let i = 0; - while (!nxt || !nxt.done) { - nxt = this.next(); - if (nxt.done) { + while (!next || !next.done) { + next = this.next(); + if (next.done) { break; } - all[i++] = nxt.value; + all[i++] = next.value; } return all; } @@ -348,6 +348,7 @@ class ChainAdapter extends Iter { } } } + class CycleAdapter extends Iter { private cache: Array; @@ -358,13 +359,13 @@ class CycleAdapter extends Iter { } override next(): IteratorResult { - const n = this.iterator.next(); - if (n.done) { + const next = this.iterator.next(); + if (next.done) { this.iterator = (> this.cache)[Symbol.iterator](); return this.iterator.next(); } else { - this.cache.push(n.value); - return n; + this.cache.push(next.value); + return next; } } }