-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Proposal: fold_self
and try_fold_self
for Iterators
#60103
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
/// Find the maximum value: | ||
/// | ||
/// ``` | ||
/// fn find_max<I>(iter: I) -> Option<I::Item> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from the behavior for Equal
, this is just Iterator::max
-- maybe a different example can be provided?
/// ``` | ||
#[inline] | ||
#[unstable(feature = "iterator_fold_self", issue = "60103")] | ||
fn fold_self<F>(mut self, mut f: F) -> Option<Self::Item> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference, in itertools, this is https://docs.rs/itertools/0.8.0/itertools/trait.Itertools.html#method.fold1 which is inspired by https://hackage.haskell.org/package/base-4.12.0.0/docs/Prelude.html#v:foldl1 in Haskell.
Co-Authored-By: Lucretiel <[email protected]>
ping from triage @joshtriplett any updates? |
Sorry for the delay, I didn't realize my fork wasn't updated with upstream master, and so I believed it when it said I was all up to date after a pull + rebase. There was a pretty substantial refactor of the |
ping from triage @Lucretiel any updates? |
Closing due to inactivity, but feel free to resubmit with the necessary changes! |
Done! Will re-opening the PR automatically bring in my latest branch changes? |
@Lucretiel I think you'll have to open another PR |
This pull request proposes & implements two new methods on Iterators:
fold_self
andtry_fold_self
. These are variants offold
andtry_fold
that use the first element in the iterator as the initial accumulator.Let me know if a public feature like this requires an RFC, or if this pull request is sufficient as place for discussion.