Skip to content

additional iterator traits for Take + Repeat/RepeatWith #114513

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

Conversation

the8472
Copy link
Member

@the8472 the8472 commented Aug 5, 2023

The iter::repeat() and iter::repeat_with() docs recommend combining them with take() to get finite iterators. Currently those combinations don't implement ExactSizeIterator or DoubleEndedIterator. This adds them where appropriate

+ impl<T: Clone> DoubleEndedIterator for Take<Repeat<T>>

+ impl<T, F> ExactSizeIterator for Take<RepeatWith<F>> where F: FnMut() -> T {}
+ impl<T: Clone> ExactSizeIterator for Take<Repeat<T>> {}

DoubleEndedIterator is not implemented for Take<RepeatWith> because the generating closure may be stateful and can only dispense items in the forward direction.

These changes are insta-stable.

The `iter::repeat()` and `iter::repeat_with()` docs recommend combining them with `take()` to
get finite iterators. Currently those combinations don't implement ExactSizeIterator
or DoubleEndedIterator. This adds them where appropriate

```diff
+ impl<T: Clone> DoubleEndedIterator for Take<Repeat<T>>

+ impl<T, F> ExactSizeIterator for Take<RepeatWith<F>> where F: FnMut() -> T {}
+ impl<T: Clone> ExactSizeIterator for Take<Repeat<T>> {}
```

`DoubleEndedIterator` is not implemented for `Take<RepeatWith>` because the
generating closure may be stateful and can only dispense items in the
forward direction.
@the8472 the8472 added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. labels Aug 5, 2023
@rustbot
Copy link
Collaborator

rustbot commented Aug 5, 2023

r? @scottmcm

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 5, 2023
@the8472
Copy link
Member Author

the8472 commented Aug 5, 2023

r? libs-api

@rustbot rustbot assigned m-ou-se and unassigned scottmcm Aug 5, 2023
@bors
Copy link
Collaborator

bors commented Sep 2, 2023

☔ The latest upstream changes (presumably #115273) made this pull request unmergeable. Please resolve the merge conflicts.

@klensy
Copy link
Contributor

klensy commented Sep 2, 2023

Similar one #106943

@the8472
Copy link
Member Author

the8472 commented Sep 2, 2023

Thanks, I missed that one. The main difference is the RepeatWith impl

@the8472
Copy link
Member Author

the8472 commented Sep 2, 2023

closing in favor of #106943

@the8472 the8472 closed this Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants