Skip to content

Commit a07e927

Browse files
author
Trevor Sears
committed
Fixed a glaring bug where the underlying Symbol.iterator implementation was removed.
1 parent dec4b3c commit a07e927

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jsdsl/iterator",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "A collection of classes that allow iteration over a predefined collection of elements.",
55
"publishConfig": {
66
"access": "public"

ts/abstract-iterable.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { Iterable } from "./iterable";
3333
* exhausted. Can be set to 'void' in the case that this AbstractIterable has infinite content. Defaults to `undefined`.
3434
*
3535
* @author Trevor Sears <[email protected]>
36-
* @version v1.0.0
36+
* @version v1.1.0
3737
* @since v0.1.0
3838
*/
3939
export abstract class AbstractIterable<E, U = undefined> implements Iterable<E, U> {
@@ -53,7 +53,34 @@ export abstract class AbstractIterable<E, U = undefined> implements Iterable<E,
5353
*/
5454
public [Symbol.iterator](): IterableIterator<E> {
5555

56-
return this.iterator()[Symbol.iterator]();
56+
return new class implements IterableIterator<E> {
57+
58+
private iterator: Iterator<E, U>;
59+
60+
public constructor(iterable: Iterable<E, U>) {
61+
62+
this.iterator = iterable.iterator();
63+
64+
}
65+
66+
public [Symbol.iterator](): IterableIterator<E> {
67+
68+
return this;
69+
70+
}
71+
72+
public next(): IteratorResult<E> {
73+
74+
return {
75+
76+
done: !this.iterator.hasNext(),
77+
value: this.iterator.next() as E
78+
79+
};
80+
81+
}
82+
83+
}(this);
5784

5885
}
5986

0 commit comments

Comments
 (0)