Ramda’s R.over() answers a transform question: apply this function to the piece a lens focuses, and give me a new structure. You pass a lens, then a function, then the data. The lens reads the focus. The function maps that value. The lens writes the result. Native JavaScript’s cousin is a copy-and-assign: [s[0].toUpperCase(), ...s.slice(1)] or nested spread. That is data-first and painful to reuse. over is data-last, so R.over(headLens, R.toUpper) is already a function of one list — ready for R.map or R.pipe.
The official sample is the whole idea. R.lensIndex(0) focuses the first item. R.toUpper turns 'foo' into 'FOO'. The leftover list is ['FOO', 'bar', 'baz']. Need only to read? That is R.view. Need a literal replacement? That is R.set. Need one top-level key with no lens? That is R.modify. Need a nested path with no lens? That is R.modifyPath.
Syntax
Call R.over. Start with this line.
Ramda
R.over(lens, fn, structure)
Call
What it does
R.over(lens, fn, structure)
Primary signature.
R.over(...)
Call the object helper.
Prefer import { over } from "ramda" when you want a named import.
Library declarations
Ramda
R.over(lens, fn, structure)
Parameters
Parameter
Description
lens
Required. Lens. A focus built with R.lens, R.lensProp, R.lensIndex, or R.lensPath.
fn
Required. Function. Called with the focused value. Its return value is written back at the same focus. Must return the next value.
structure
Required. Any. The source object, array, or nested tree. It is not mutated when the lens setter is immutable.
Return Value
Return Value
Description
Same shape as structure
A new structure whose focused slot is fn(view(lens, structure)). Sibling keys and other indexes stay. Nested values off the path stay shared by reference.
Ramda Examples
📚 Getting Started
The official Ramda array sample, then the classic object lens with negate.
R.lensProp('x') is R.lens(R.prop('x'), R.assoc('x')). negate turns 1 into -1. assoc writes that on a clone, so orig.x is still 1. This leftover is the same sample the lensProp docs show for over.
📈 Practical Patterns
Compare view, set, and modify, then a nested path, then a curried helper and a missing-key pitfall.
Example 3 — vs view, set, and modify
Same xLens. view reads. set writes a literal. over maps a function. modify matches over for one existing key.
set never looks at the current 1. over does. modify agrees here because the key exists. Prefer modify when you will never reuse a lens. Prefer over when the same focus must also support view and set, or when the slot is an index or a nested path.
Example 4 — Nested lensPath
Walk user.name. Uppercase the name. Sibling city stays. The original nested object is not mutated.
R.lensPath clones along the path and copies sibling keys. R.lensProp('name') would miss, because name is not top-level. R.modifyPath is the no-lens cousin of this leftover.
Example 5 — Curry, Map, Missing Key
Fill the lens and function to map over rows. A missing key still runs fn on undefined — unlike modify, which skips.
bumpAge is a function of one object. Map it over people. On {}, view of 'x' is undefined, R.inc(undefined) is NaN, and assoc writes that key. JSON.stringify prints NaN as null — the Try-it lab shows that JSON line, while the live leftover is still a number NaN. modify does not call inc when the key is missing, so you get {} back.
Compatibility
Browser Support
R.over() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Ramda 0.16.0+ · Any JS runtime
Ramda.js R.over()
Load Ramda 0.16.0 or later via CDN or npm, then call R.over with a lens, a function, and a structure. No extra browser API is required.
100%With Ramda 0.16.0+
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
R.over()Universal
Bottom line: Safe in any project that includes Ramda 0.16.0 or later. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node. These labs use [email protected].
Frequently Asked Questions
R.over(lens, fn, structure) applies fn to the value focused by lens, then writes that result back. You get a new structure. Added in v0.16.0. The original is not mutated when the lens setter is immutable.
const headLens = R.lensIndex(0). R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']) is ['FOO', 'bar', 'baz']. Only the first item is transformed.
view only reads the focus. set replaces the focus with a value you already know. over reads the focus, runs a function, and sets the result. over(lens, fn, s) is the same idea as set(lens, fn(view(lens, s)), s).
modify updates one top-level key. modifyPath updates a nested path. over uses any lens: lensProp, lensIndex, lensPath, or a custom R.lens. For one key, over(lensProp('age'), R.add(1), person) matches modify('age', R.add(1), person) when the key exists.
fn still runs on whatever view returns, often undefined. R.over(R.lensProp('x'), R.inc, {}) becomes {x: NaN} because inc(undefined) is NaN. modify skips a missing key and returns the original object.
No. R.over is a stable Ramda object helper from v0.16.0. It is not deprecated, experimental, or non-standard.