Skip to content

add running #51

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

Closed
wants to merge 5 commits into from
Closed

add running #51

wants to merge 5 commits into from

Conversation

ebonnal
Copy link
Owner

@ebonnal ebonnal commented Jan 4, 2025

Adds the behavior of itertools.accumulate (aka .scan in Scala/Haskell).

Examples

from streamable import running

cumulative_sum = (
    Stream(range(10))
    .map(running(lambda cumsum, i: cumsum + i, initial=0))
)

assert list(cumulative_sum) == [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]

fibonacci = (
    Stream(range(10))
    .map(running(lambda acc, _: (acc[1], acc[0] + acc[1]), initial=(0, 1)))
    .map(itemgetter(0))
)

assert list(fibonacci) == [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

@ebonnal ebonnal added the feature New feature or request, modifies library API label Jan 4, 2025
Copy link

codecov bot commented Jan 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (53a9314) to head (1a9e228).

Additional details and impacted files
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ebonnal ebonnal changed the base branch from main to 1.4.5 January 4, 2025 22:09
@ebonnal
Copy link
Owner Author

ebonnal commented Jan 4, 2025

As discussed @pierrenodet

Next steps I have in mind, please feel free to complete:

  • validate that this is the most elegant way to add this behavior
  • validate that the signature follows conventions existing elsewhere
  • more unit tests (e.g. are we happy with how it behaves in case exceptions are thrown by the binary func?)
  • find a concise yet explicit description for the README and the docstring (we can get inspiration from the itertools.accumulate's doc)
  • validate the choice of the example in the README

@ebonnal ebonnal changed the title add running add running Jan 4, 2025
@ebonnal ebonnal force-pushed the 1.4.5 branch 4 times, most recently from 27b9718 to 9d789e2 Compare January 6, 2025 18:45
Base automatically changed from 1.4.5 to main January 6, 2025 23:23
@ebonnal ebonnal changed the base branch from main to 1.4.7 January 25, 2025 23:20
@ebonnal ebonnal force-pushed the 1.4.7 branch 3 times, most recently from 584fa0e to 53a9314 Compare January 26, 2025 15:44
ebonnal and others added 5 commits January 26, 2025 15:48
Co-authored-by: pierrenodet <[email protected]>
@ebonnal ebonnal deleted the branch 1.4.7 March 10, 2025 14:43
@ebonnal ebonnal closed this Mar 10, 2025
@ebonnal
Copy link
Owner Author

ebonnal commented Mar 12, 2025

moved to #87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request, modifies library API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant