Skip to content

Commit

Permalink
Fixed a glaring bug where the underlying Symbol.iterator implementa…
Browse files Browse the repository at this point in the history
…tion was removed.
  • Loading branch information
Trevor Sears committed Sep 10, 2021
1 parent dec4b3c commit a07e927
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsdsl/iterator",
"version": "1.0.1",
"version": "1.1.0",
"description": "A collection of classes that allow iteration over a predefined collection of elements.",
"publishConfig": {
"access": "public"
Expand Down
31 changes: 29 additions & 2 deletions ts/abstract-iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { Iterable } from "./iterable";
* exhausted. Can be set to 'void' in the case that this AbstractIterable has infinite content. Defaults to `undefined`.
*
* @author Trevor Sears <[email protected]>
* @version v1.0.0
* @version v1.1.0
* @since v0.1.0
*/
export abstract class AbstractIterable<E, U = undefined> implements Iterable<E, U> {
Expand All @@ -53,7 +53,34 @@ export abstract class AbstractIterable<E, U = undefined> implements Iterable<E,
*/
public [Symbol.iterator](): IterableIterator<E> {

return this.iterator()[Symbol.iterator]();
return new class implements IterableIterator<E> {

private iterator: Iterator<E, U>;

public constructor(iterable: Iterable<E, U>) {

this.iterator = iterable.iterator();

}

public [Symbol.iterator](): IterableIterator<E> {

return this;

}

public next(): IteratorResult<E> {

return {

done: !this.iterator.hasNext(),
value: this.iterator.next() as E

};

}

}(this);

}

Expand Down

0 comments on commit a07e927

Please sign in to comment.