Repository navigation
Fix keys of an interposed Seq iterated in reverse - #2310
Merged
Merged
Conversation
`interpose` numbered its keys from 0 in iteration order, so iterating it in reverse gave the last value key 0. `Seq([1, 2, 3]).interpose(0) .lastIndexOf(1)` returned 4 instead of 0. Count down from the size of the interposed sequence when iterating in reverse. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Thanks for testing all these reverse cases and submitting fixes! I bet without claude, most people wouldn't write or even try to read code like |
Contributor
Author
|
Ha, true 😄 Thanks for the quick reviews and merges! |
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.
interposenumbers its keys in iteration order, so when it is iterated in reverse the last value gets key 0:List#interposeis fine because the List is built in a forward pass, but a lazy Seq (includingRange) hits it throughlastIndexOf,findLastIndex,findLastEntry,reduceRightand reversed iterators.It's the same problem as #2309 (filter), in
interposeFactory. In reverse, keys now count down from the size of the interposed sequence. When that size is unknown (e.g. afterfilter),ensureSizeworks it out first, like #2309 does.The new test in
__tests__/interpose.tscovers a Seq of known and unknown size, through both__iterateand__iterator. It fails onmainand passes with this change. The same code is on6.x.I used Claude Code to write this change.