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

Make truncate a no-op when count=None and when=None #57

Closed
mjkanji opened this issue Jan 21, 2025 · 2 comments
Closed

Make truncate a no-op when count=None and when=None #57

mjkanji opened this issue Jan 21, 2025 · 2 comments
Labels
TODO Added to roadmap

Comments

@mjkanji
Copy link
Contributor

mjkanji commented Jan 21, 2025

It's a common pattern to have some limit that you set to a small int for testing and None for prod jobs. streamable currently raises an error when both count and when equal None. Instead, it should be a no-op that simply returns the input stream/iterable without doing anything.

This is especially useful when working with env vars (where if the value is not set, then os.getenv returns None).

# script.py
def my_func():
  return Stream(range(1e6)).truncate(os.getenv("LIMIT")).map(some_expensive_op)

# for testing
LIMIT=10 python script.py

# for prod
python script.py
@mjkanji mjkanji changed the title Make truncate a no-op when count=None and when=None Make truncate a no-op when count=None and when=None Jan 21, 2025
@ebonnal
Copy link
Owner

ebonnal commented Jan 21, 2025

Hey @mjkanji 👋🏻

Definitely makes sense, could you review #59 which also applies your suggestion to .skip?

@mjkanji
Copy link
Contributor Author

mjkanji commented Jan 21, 2025

@ebonnal Thank you for the quick response — and #59 Looks good to me!

@ebonnal ebonnal added the TODO Added to roadmap label Jan 22, 2025
ebonnal added a commit that referenced this issue Jan 23, 2025
… `.skip`: ok when both `count` and `until` are set (#59)
ebonnal added a commit that referenced this issue Jan 23, 2025
… `.skip`: ok when both `count` and `until` are set (#59)
ebonnal added a commit that referenced this issue Jan 23, 2025
… `.skip`: ok when both `count` and `until` are set (#59)
ebonnal added a commit that referenced this issue Jan 24, 2025
… `.skip`: ok when both `count` and `until` are set (#59)
ebonnal added a commit that referenced this issue Jan 25, 2025
… `.skip`: ok when both `count` and `until` are set (#59)
ebonnal added a commit that referenced this issue Jan 26, 2025
… `.skip`: ok when both `count` and `until` are set (#59)
ebonnal added a commit that referenced this issue Jan 26, 2025
… `.skip`: ok when both `count` and `until` are set (#59)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TODO Added to roadmap
Projects
None yet
Development

No branches or pull requests

2 participants