Skip to content

Conversation

hkBst
Copy link
Member

@hkBst hkBst commented Sep 17, 2025

A continuation of #146410 which changes the direct count impl for a fold impl, to which the default count delegates. Also added tests for the new behavior.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 17, 2025

r? @ibraheemdev

rustbot has assigned @ibraheemdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@hkBst
Copy link
Member Author

hkBst commented Sep 17, 2025

r? @jhpratt

@rustbot rustbot assigned jhpratt and unassigned ibraheemdev Sep 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 17, 2025

jhpratt is not on the review rotation at the moment.
They may take a while to respond.

@asquared31415
Copy link
Contributor

Arguably one could use the infinite fold for side effects? It would be kind of weird though.

@hkBst
Copy link
Member Author

hkBst commented Sep 17, 2025

@asquared31415 true, I may have to take that out then...

@LIParadise
Copy link

LIParadise commented Sep 18, 2025

Adapters like std::iter::Map may override only Iterator::fold but Iterator::last, meaning assert_eq!(repeat(42).last(), repeat(42).map(std::convert::identity).last()) would fail: the former returns Some(42) while the latter delegates to <Repeat as Iterator>::fold then panics, no?

@hkBst
Copy link
Member Author

hkBst commented Sep 18, 2025

@LIParadise I believe that assert should hold, but let me add a test.

@hkBst
Copy link
Member Author

hkBst commented Sep 18, 2025

@LIParadise I was wrong, but I was able to fix it...

@LIParadise
Copy link

If that's the case, I'm afraid there are quite a few types that's Iterator that need to be taken into consideration, too, for instance.

@LIParadise
Copy link

LIParadise commented Sep 18, 2025

Also crates like itertools might have a word or two.

Iterator is nice partly because next implies all other methods; such default method delegations are handy s.t. we definitely don't want to give up on them (and also backwards compatibility), but OTOH they imply whenever one has an implementation that departs from the default implementation would most likely lead to issues like this: iterator adapter libraries has to be aware of such possibility and delegate accordingly to preserve the inner type's semantics.

Part of me agree that <Repeat as Iterator>::last should evaluate the same as <Repeat as DoubleEndedIterator>::next_back, but another part of me thinks there's more to this issue. Iterator's default implementation means calling next i.e. moving forward should give one required results. DoubleEndedIterator is going from back. Are there mathematical equivalence between ordinals/supertasks and their reverse version (sorry but my mathematics are poor to the point I don't know how to formally define the latter)?

@hkBst
Copy link
Member Author

hkBst commented Sep 18, 2025

@LIParadise I think #146410 (comment) describes it well. Alternatively you can imagine two infinite sequences with their infinite ends glued together. It amounts to the same thing.

@jhpratt
Copy link
Member

jhpratt commented Sep 19, 2025

I'm off-rotation as I don't have the time to handle nontrivial reviews at the moment.

r? libs

@rustbot rustbot assigned Mark-Simulacrum and unassigned jhpratt Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants