Ramda.js R.over() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

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)
CallWhat 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

ParameterDescription
lensRequired. Lens. A focus built with R.lens, R.lensProp, R.lensIndex, or R.lensPath.
fnRequired. Function. Called with the focused value. Its return value is written back at the same focus. Must return the next value.
structureRequired. Any. The source object, array, or nested tree. It is not mutated when the lens setter is immutable.

Return Value

Return ValueDescription
Same shape as structureA 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.

Example 1 — Official headLens + toUpper

Focus index 0. Map toUpper. The other items stay.

Ramda
const headLens = R.lensIndex(0);

R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']);
//=> ['FOO', 'bar', 'baz']
Try It Yourself

How It Works

R.lensIndex(0) focuses the first slot. over views 'foo', applies toUpper, and sets 'FOO' on a new array. That is the docs sample from ramdajs.com.

Example 2 — lensProp + Negate

The same helper on an object. y stays 2. The original point is not mutated.

Ramda
const xLens = R.lensProp('x');
const orig = {x: 1, y: 2};

R.over(xLens, R.negate, orig);
//=> {x: -1, y: 2}

orig;
//=> {x: 1, y: 2}
Try It Yourself

How It Works

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.

Ramda
const xLens = R.lensProp('x');
const point = {x: 1, y: 2};

R.view(xLens, point);
//=> 1

R.set(xLens, 4, point);
//=> {x: 4, y: 2}

R.over(xLens, R.negate, point);
//=> {x: -1, y: 2}

R.modify('x', R.negate, point);
//=> {x: -1, y: 2}
Try It Yourself

How It Works

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.

Ramda
const nameLens = R.lensPath(['user', 'name']);
const orig = { user: { name: 'ada', city: 'Paris' } };

R.over(nameLens, R.toUpper, orig);
//=> { user: { name: 'ADA', city: 'Paris' } }

orig;
//=> { user: { name: 'ada', city: 'Paris' } }
Try It Yourself

How It Works

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.

Ramda
const bumpAge = R.over(R.lensProp('age'), R.add(1));

R.map(bumpAge, [{age: 20}, {age: 30}]);
//=> [{age: 21}, {age: 31}]

R.over(R.lensProp('x'), R.inc, {});
//=> {x: NaN}

R.modify('x', R.inc, {});
//=> {}
Try It Yourself

How It Works

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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All 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.

Continue to R.path()

Learn how to read a nested trail using Ramda R.path().

R.path() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful