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

New combinator: multi::reduce #1578

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bertptrs
Copy link

@bertptrs bertptrs commented Dec 3, 2022

This PR adds a new combinator: multi::reduce. It is essentially a special case of multi::fold_many1 where the accumulator type is the same as the parsed type.

Analogous to Iterator::reduce, this new combinator takes the first parsed element as the initial value rather than use a separate initializer function. This is useful in many cases, but most commonly for when you do not have an easy base element for your reduction, for example when computing a minimum over a list of elements without a well-defined absolute maximum.

Aside from this new combinator, the PR also includes the following changes (in separate commits for easy review):

  • Fix a test for a specific struct size. Apparently rustc got smarter?
  • Refactor shared code between fold_many0 and fold_many1
  • Breaking: change the infinite loop error for fold_many1 from Error to Failure. I believe this was always the correct version since it indicates a programming error and not a data issue.

Tests for new code included.

@bertptrs
Copy link
Author

This PR is now almost a year old and has various conflicts with the main branch so it cannot be merged but I would still like the combinator added here.

Is this something that could be added? If so, I'll clean up the PR so that it works again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant