8000 Fix the out-of-range R.over example in lensIndex docs by SwastikTripathi · Pull Request #3590 · ramda/ramda · GitHub
[go: up one dir, main page]

Skip to content

Fix the out-of-range R.over example in lensIndex docs - #3590

Open
SwastikTripathi wants to merge 1 commit into
ramda:masterfrom
SwastikTripathi:docs/lens-index-out-of-range-over
Open

SwastikTripathi wants to merge 1 commit into
ramda:masterfrom
SwastikTripathi:docs/lens-index-out-of-range-over

Conversation

@SwastikTripathi
@SwastikTripathi SwastikTripathi commented Nov 9, 2026 •
Copy link
Copy Markdown

The lensIndex docs say an out-of-range index returns the original list, and show:

R.over(R.lensIndex(-4), R.toUpper, ['a', 'b', 'c']); //=> ['a', 'b', 'c']

That line throws TypeError: undefined does not have a method named "toUpperCase". over first views the focus, which is undefined for a missing index, and calls the function with it. Only after that does update ignore the out-of-range index and return the list unchanged. So the result is the original list only when the function accepts undefined.

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 @example line that has a //=> result against ramda 0.32.0 (566 checked lines): this was the only one that threw. lensIndex is the same on master.

Also added tests for set and over with an index past either end, and one that over passes undefined to 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.

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>
@github-actions
github-actions Bot commented Nov 9, 2026
Copy link
Copy Markdown
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 )
================================================================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0