-
Notifications
You must be signed in to change notification settings - Fork 5
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
Stream.of(...)
consumes the underlying iterable eagerly
#94
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Thanks @adrian-herscu for your helping improve pystreamapi! You are right that generators are not handled as they should be. The problem is very visible in this snippet: def infinite_gen():
yield from iter(int, 1)
Stream.of(infinite_gen()) \
.map(lambda x: x * 2) \ # 💀 Infinite loop
.limit(10) \
.for_each(print) Currently, you have to position def infinite_gen():
yield from iter(int, 1)
Stream.of(infinite_gen()) \
.limit(10) \
.map(lambda x: x * 2) \
.for_each(print) # 👍 Working perfectly Pystreamapi is executing all operations lazy, but internally uses lists, being the reason the whole generator is consumed with the first intermediate operation. The best solution is to use generators internally so the generators are not completeley consumed. Note: The missing pattern in your output is not necessarily always an issue, since there are intermediate ops which require the whole generator to be consumed (sorted, distinct, etc.) Tasks to completeThis issue can be split into the following three tasks
|
…generators-in-sequential-streams' into bugfix/#94/support-for-infinite-generators-in-sequential-streams
…ite-generators-in-sequential-streams 🐛 Fix sequential stream consuming source eager
Describe the bug
Stream.of(...)
consumes the underlying iterable eagerly.Perhaps there is another way of wrapping an iterable?
To Reproduce
Expected behavior
should_stream2
should behave the same asshould_stream0
by printing>>
interleaved with numbers.Machine (please complete the following information):
The text was updated successfully, but these errors were encountered: