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

Fix loading an extra element when not necessary #39

Merged
merged 2 commits into from
Feb 23, 2025

Conversation

Baptouuuu
Copy link
Member

Problem

When using a lazy Sequence with a take call it would load an extra element from the generator that is never used.

In most cases this is not very problematic.

But working on Innmind/io#1 it causes problems as it ends up trying to load a value from a stream that is no longer readable and ends up with an error.

Solution

  • Add a pre-condition if the size is 0
  • Stop the generator before loading the next value

@Baptouuuu Baptouuuu added the bug Something isn't working label Feb 23, 2025
@Baptouuuu Baptouuuu self-assigned this Feb 23, 2025
Copy link

codecov bot commented Feb 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.80%. Comparing base (6f6ca72) to head (76fa470).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop      #39      +/-   ##
=============================================
- Coverage      97.91%   97.80%   -0.11%     
- Complexity      1049     1050       +1     
=============================================
  Files             72       72              
  Lines           4216     4235      +19     
=============================================
+ Hits            4128     4142      +14     
- Misses            88       93       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Baptouuuu Baptouuuu merged commit 10d2ac3 into develop Feb 23, 2025
32 of 33 checks passed
@Baptouuuu Baptouuuu deleted the fix-lazy-sequence-take branch February 23, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant