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

parse_input does not currently support Generators #1

Closed
ionite34 opened this issue Sep 3, 2022 · 3 comments
Closed

parse_input does not currently support Generators #1

ionite34 opened this issue Sep 3, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@ionite34
Copy link

ionite34 commented Sep 3, 2022

It is quite common to use generators to handle input parsing:

def parse_input(lines: list[str]):
    for line in lines:
       yield re.match('...', line).groups()

Currently, this does not work as the runner passes the same generator into Part 1 and Part 2, which is exhausted in Part 2 as it has already been iterated in Part 1.

This can be implemented relatively easily if desired by detecting a Generator with isinstance and making a copy for Part 2.

@fergusch
Copy link
Owner

fergusch commented Sep 3, 2022

I'm a little rusty with generators, but I think this should work: afce205

Thoughts?

@fergusch fergusch added the enhancement New feature or request label Sep 3, 2022
@ionite34
Copy link
Author

ionite34 commented Sep 4, 2022

I'm a little rusty with generators, but I think this should work: afce205

Thoughts?

Thanks for the quick implementation!

This is probably more appropriate than GeneratorType:

from collections.abc import Generator

if isinstance(data, Generator):

But otherwise, everything else looks good!

@fergusch
Copy link
Owner

fergusch commented Sep 4, 2022

Awesome, changes will be included in the next release. Closing this issue.

@fergusch fergusch closed this as completed Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants