Fix Product2
's indexing logic
#26
Merged
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.
This PR changes the way
Product2.endIndex
is represented: instead of(base1.endIndex, base2.endIndex)
, it is now(base1.endIndex, base2.startIndex)
.The latter turns out to be a more natural way of representing the "past the end" index because it is exactly the index after the last valid index
(lastValidIndexOfBase1, lastValidIndexOfBase2)
according to the existing mechanism of advancing any other index ofProduct2
. As a result, the methodsindex(before:)
,index(after:)
, anddistance(from:to:)
don't need any custom logic to deal withendIndex
.endIndex
wasn't handled correctly everywhere so this also ends up fixing bugs inindex(before:)
anddistance(from:to:)
.Checklist