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

feat(corelib): iter::adapters::Map #6949

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

Conversation

julio4
Copy link
Contributor

@julio4 julio4 commented Dec 28, 2024

This is mostly an exploratory PR to test implementation of iterator adapters, i.e. functions that take an Iterator to return another Iterator. It's really useful as any type that implement IntoIterator can benefits from these adapters, and it also enables function chaining on iterators.

Added a first implementation of iter::adapters::Map:

let mut i = 1;
for elem in (1..4_u8).into_iter().map(|x| 2 * x).map(|x| x + 1) {
    assert_eq!(elem, i * 2 + 1);
    i += 1;
}

I'm curious to know if an implementation of ops::FnMut would be possible, to be able to perform function calls with a reference? With it I believe the efficiency of these adapters can be greatly improved to avoid excessive copy/drop.

Feedback welcome on both the current implementation and potential optimization

@reviewable-StarkWare
Copy link

This change is Reviewable

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.

2 participants