Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Symbol.iterator on Expansion class #84

Open
Agapurnis opened this issue Mar 3, 2023 · 0 comments
Open

Implement Symbol.iterator on Expansion class #84

Agapurnis opened this issue Mar 3, 2023 · 0 comments

Comments

@Agapurnis
Copy link

Currently to iterate over an expander you must call getIterator:

const digitExpander = expand(/\d/);

for (const digit of digitExpander.getIterator()) {
	// ...
}

By implementing Symbol.iterator, you would be able to do the following:

const digitExpander = expand(/\d/);

for (const digit of digitExpander) {
	// ...
}

This can be done by changing the Expansion like so:

export default class Expansion {
	// ... (omitted) ....

	/**
	 * Alias for `getIterator`
	 */
	public [Symbol.iterator]: () => IterableIterator<string>;

	// ... (omitted) ....

	public constructor(getIterator: IterableSource, count: Expansion['count']) {
		this.getIterator = toIterable(getIterator);
		this[Symbol.iterator] = this.getIterator;
		this.count = count;
	}
}

I'd contribute it myself, but I'm not sure how exactly you would like it styled, and would probably end up messing something up, haha. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant