Skip to content

Implement RandomAccessIterator where possible #8108

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
bluss opened this issue Jul 29, 2013 · 7 comments
Closed

Implement RandomAccessIterator where possible #8108

bluss opened this issue Jul 29, 2013 · 7 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@bluss
Copy link
Member

bluss commented Jul 29, 2013

Adaptors like Enumerate, Map, Zip, Take etc need to implement Random access.

I'm working on this.

@huonw
Copy link
Member

huonw commented Jul 29, 2013

One has to be careful with Map because it will mean that the mapped function can get evaluated multiple times (if you access a specific element more than once).

@bluss
Copy link
Member Author

bluss commented Jul 29, 2013

That's correct. Since the introduction of double-ended iterator, you can't be sure of the order the map function is invoked either (could be alternating front and back). I don't know how to best handle this.

@bluss
Copy link
Member Author

bluss commented Jul 29, 2013

We could provide a separate adaptor that only takes an extern fn. That Map adaptor will be clonable and random access, and the standard one will not? In the end we don't have any purity guarantees either way.

@huonw
Copy link
Member

huonw commented Jul 29, 2013

Not sure that such a restriction is worth it, either no functions or all functions (at least until we get an effects system); since there's no guarantee that extern fn's are idempotent/pure (e.g. fn increment_and_get_network_resource, or something using TLS), and many closure would be (e.g. |&x| x).

bors added a commit that referenced this issue Jul 30, 2013
Implement RandomAccessIterator (RAI) where possible, for Iterator adaptors such as Map, Enumerate, Peek, Skip, Take, Cycle, where the adapted iterator is already RAI, and for collections where it is relevant (ringbuf and bitv).

After discussion with thestinger, remove the RAI impl for VecMutIterator, we cannot soundly provide mutable access with this trait.

Implement Extendable everywhere FromIterator is already implemented.

Fixes issue #8108.
@emberian
Copy link
Member

emberian commented Apr 7, 2014

Hasn't been fixed entirely, #8120 added a bunch of impls.

@bluss
Copy link
Member Author

bluss commented Aug 24, 2014

"RAI" seems to never have reached usefulness. I'm still not sure if it should even be in rust.

@steveklabnik
Copy link
Member

This ticket isn't particularly actionable, if anything is still missing, please open a new one with specifics, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants