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
[SR-7797] Incorrect results using subscript in lazy collection #50336
Comments
Lazy collections use the same indexes as their underlying collections, so (as I understand it) it's assumed that if you do direct access using an index, you want an element from the underlying collection. If you want the first element, you can use @lorentey, does that sound correct? |
It does! The lazy filter collection reuses the index type of the original collection, although typically only a subset of the original indices are valid in it. In this case, This wrinkle doesn't occur when using the collection APIs to generate indices in One way to prevent these issues would be to wrap the base collection's indices into a new |
I think the main reason they use the underlying collection's index is so that you can use things like |
Comment by Petro Korienev (JIRA) While it sounds reasonable, it's really confusing for the developers because:
The possible solution will be to run complete lazy calculation chain once:
and then cache the result into some `_calculated` property discarding `_base` collection? If changes to LazyCollection are off the roadmap for Swift 4.2 minors / Swift 5, probably adding proper documentation for this case can be considered to be taken into implementation? Thanks in advance |
/cc @natecook1000 |
Environment
Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Xcode: Version 9.3 (9E145)
Additional Detail from JIRA
md5: 1db7d23c2a2c01e9614b9f873e4d2a63
Issue Description:
The current swift version has a bug when lazy and non-lazy collections behaves differently when accessed via subscript
Lazy Collection
Output:
Non-Lazy Collection
Output:
So lazy collection behaves totally different from the non-lazy collection, which doesn't seem like a correct behaviour
The text was updated successfully, but these errors were encountered: