implement DoubleEndedIterator for 1d LanesIter#1237
Merged
bluss merged 1 commit intorust-ndarray:masterfrom Mar 10, 2024
Merged
implement DoubleEndedIterator for 1d LanesIter#1237bluss merged 1 commit intorust-ndarray:masterfrom
LanesIter#1237bluss merged 1 commit intorust-ndarray:masterfrom
Conversation
bluss
reviewed
Mar 10, 2024
src/iterators/mod.rs
Outdated
|
|
||
| impl<'a, A, D> DoubleEndedIterator for LanesIter<'a, A, D> | ||
| where | ||
| D: Dimension, |
Member
There was a problem hiding this comment.
I expected this to be limited to the case where D=Ix1. Just like how .iter()'s Iter works. I think it's better that way, then the Baseiter does not leak out (it's in the where clause, that's a leak of internals into public API.)
Member
There was a problem hiding this comment.
Fixed that, and also applied the same change to LanesIterMut - it and LanesIter must of course change together.
5cb455d to
0ec6ede
Compare
This is especially useful when one wants to iterate over rows or columns of a 2d array in reverse. Co-authored-by: Ulrik Sverdrup <bluss@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a project I wanted to iterate over the rows and columns of a 2d array in reverse but while
rowsandcolumnsexist, the resultingLanesIterdoes not implementDoubleEndedIteratoras of yet. It is possible to use indexing viarowwith reversed indices but that is less ergonomic.This PR fixes this at least for 1d
LanesIterand now allows one to do:The implementation just delegates to the underlying 1d
Baseiterwhich implementsDoubleEndedIterator.The trait is not implemented for higher dimensions however, which would need some additional work.