Skip to content

Commit

Permalink
Merge pull request #26 from hoodie/feature/ci
Browse files Browse the repository at this point in the history
setup ci
  • Loading branch information
hoodie authored Dec 23, 2024
2 parents a2b42f4 + c0ffeeb commit 1328c93
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
*.js
yarn-error.log
docs
coverage
3 changes: 3 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 17 additions & 16 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,15 @@ class SizedIter<T> extends Iter<T> implements SizedLazyIterator<T> {
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;
}
}

Expand All @@ -314,14 +314,14 @@ class SizedIter<T> extends Iter<T> implements SizedLazyIterator<T> {

override intoArray(): T[] {
const all = new Array<T>(this.size);
let nxt: IteratorResult<T> | undefined;
let next: IteratorResult<T> | 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;
}
Expand All @@ -348,6 +348,7 @@ class ChainAdapter<T, U> extends Iter<T | U> {
}
}
}

class CycleAdapter<T> extends Iter<T> {
private cache: Array<T>;

Expand All @@ -358,13 +359,13 @@ class CycleAdapter<T> extends Iter<T> {
}

override next(): IteratorResult<T> {
const n = this.iterator.next();
if (n.done) {
const next = this.iterator.next();
if (next.done) {
this.iterator = (<Array<T>> this.cache)[Symbol.iterator]();
return this.iterator.next();
} else {
this.cache.push(n.value);
return n;
this.cache.push(next.value);
return next;
}
}
}
Expand Down

0 comments on commit 1328c93

Please sign in to comment.