Ramda’s R.view() answers a read question: what value sits at the piece a lens focuses? You pass a lens, then the data. The lens getter runs. You get that focused leftover, not a copy of the whole object. Native JavaScript’s cousin is obj.x or R.prop('x', obj). That is one key. view is data-last, so R.view(xLens) is already a function of one object — ready for R.map or R.pipe.
The official sample is the whole idea. R.lensProp('x') focuses the x key. Viewing {x: 1, y: 2} yields 1. Viewing {x: 4, y: 2} yields 4. Need to write a literal? That is R.set. Need a function of the current value? That is R.over. Need one top-level key with no lens? That is R.prop. Need a nested path with no lens? That is R.path. Previous Object helper is R.valuesIn. Next is R.where.
Syntax
Call R.view. Start with this line.
Ramda
R.view(lens, structure)
Call
What it does
R.view(lens, structure)
Primary signature.
R.view(...)
Call the object helper.
Prefer import { view } from "ramda" when you want a named import.
Library declarations
Ramda
R.view(lens, structure)
Parameters
Parameter
Description
lens
Required. Lens. A focus built with R.lens, R.lensProp, R.lensIndex, or R.lensPath.
structure
Required. Any. The source object, array, or nested tree. Docs call this x. It is not mutated.
Return Value
Return Value
Description
Focused leftover
Whatever the lens getter returns. A missing key is usually undefined. The source structure is not copied.
Ramda Examples
📚 Getting Started
The official Ramda object sample, then the same lens compared with set and over.
Example 1 — Official xLens
Focus x. Read 1, then read 4. y is never returned.
view never copies the object. set and over do. prop agrees here because the key is top-level. Prefer prop when you will never reuse a lens. Prefer view when the same focus must also support set and over, or when the slot is an index or a nested path.
📈 Practical Patterns
An index, a nested path, a missing key, then a curried helper mapped over rows.
Example 3 — lensIndex
Read the first array slot. The rest of the list is never returned.
R.lensIndex(0) is the same focus R.over uses in its official head sample. view stops after the getter. over would write a transformed item back into a new array.
Example 4 — Nested lensPath and a Missing Key
Read a nested name. A missing key is undefined. The original tree is not copied.
R.lensPath walks the trail. R.lensProp('name') would miss, because name is not top-level. R.path is the no-lens cousin. Labs that print with JSON.stringify turn undefined into null — these outputs use String() for the hole.
Example 5 — Curry and Map
Fill the lens to pluck one field from many rows. The leftover is a function of one object.
Because view is arity 2, filling the lens leaves a function of one record. Native row.x would need an arrow wrapper on every row. Need to write instead? Switch to R.set or R.over.
Compatibility
Browser Support
R.view() 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.view()
Load Ramda 0.16.0 or later via CDN or npm, then call R.view with a lens 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.view()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.view(lens, structure) reads the value focused by lens. You get that focused leftover, not a copy of the whole structure. Added in v0.16.0. The original is not mutated.
const xLens = R.lensProp('x'). R.view(xLens, {x: 1, y: 2}) is 1. R.view(xLens, {x: 4, y: 2}) is 4.
view only reads the focus. set replaces the focus with a value you already know. over reads the focus, runs a function, and writes the result. view does not copy the structure.
prop reads one top-level key. path reads a nested trail. view uses any lens: lensProp, lensIndex, lensPath, or a custom R.lens. For one key, view(lensProp('x'), obj) matches prop('x', obj).
view returns whatever the getter returns, often undefined. R.view(R.lensProp('x'), {}) is undefined. JSON.stringify turns that hole into null in labs; use String() when you need the real hole.
No. R.view is a stable Ramda object helper from v0.16.0. It is not deprecated, experimental, or non-standard.