Repository navigation
Fix the out-of-range R.over example in lensIndex docs - #3590
Open
SwastikTripathi wants to merge 1 commit into
Open
SwastikTripathi wants to merge 1 commit into
SwastikTripathi wants to merge 1 commit into
Conversation
R.over(R.lensIndex(-4), R.toUpper, ['a', 'b', 'c']) throws, because over calls the function with the undefined value at the missing index before update ignores the index. Use R.always in the example and add tests for set and over with an index that does not exist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coverage Summary> ramda@0.32.0 coverage:summary
> BABEL_ENV=cjs nyc --reporter=text-summary mocha -- --reporter=min --require @babel/register
�[2J�[1;3H
1264 passing (1s)
=============================== Coverage summary ===============================
Statements : 94.22% ( 2574/2732 )
Branches : 86.33% ( 1017/1178 )
Functions : 93.57% ( 568/607 )
Lines : 94.48% ( 2414/2555 )
================================================================================ |
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.
The
lensIndexdocs say an out-of-range index returns the original list, and show:That line throws
TypeError: undefined does not have a method named "toUpperCase".overfirst views the focus, which isundefinedfor a missing index, and calls the function with it. Only after that doesupdateignore the out-of-range index and return the list unchanged. So the result is the original list only when the function acceptsundefined.The example now uses
R.always('x'), which shows the point (the list comes back unchanged even though the function returns a value). No code change.I found it by running every
@exampleline that has a//=>result against ramda 0.32.0 (566 checked lines): this was the only one that threw.lensIndexis the same on master.Also added tests for
setandoverwith an index past either end, and one thatoverpassesundefinedto the function, since none of the out-of-range behavior was covered. They pass on master.npm run spec(1267 passing) and eslint on the two files are clean.I used Claude Code (AI) to find and write this change and verified it as described.