Ramda.js R.identity() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

A function that returns whatever you pass in — unchanged. It is the named version of the arrow function x => x. Part of Ramda Function since v0.1.0 (stable — not deprecated, experimental, or non-standard).

Why it exists: many Ramda helpers need a function. When the right behavior is “keep the value,” pass R.identity.

Syntax

Call R.identity. Start with this line.

Ramda
R.identity(x) or pass R.identity as a callback Signature a → a
CallWhat it does
R.identity(x) or pass R.identity as a callback Signature a → aPrimary signature.
R.identity(...)Call the function helper.

Prefer import { identity } from "ramda" when you want a named import.

Library declarations
Ramda
R.identity(x) or pass R.identity as a callback Signature a → a

Parameters

ParameterDescription
xRequired. Any value; returned exactly as given
Extra argsOptional. Ignored

Return Value

Return ValueDescription
*The same x (same reference for objects)

Ramda Examples

Example 1 — Official Samples

Both lines come from the Ramda docs: a number, then the same object back.

Ramda
console.log(R.identity(1));
// → 1

const obj = {};
console.log(R.identity(obj) === obj);
// → true
Try It Yourself

How It Works

  1. Pass a number. R.identity(1) returns 1 — nothing is added or changed.
  2. Create one object. obj points to a single empty object in memory.
  3. Pass the object. Identity hands back that same object, not a copy.
  4. Compare. === checks the reference, so the result is true.

Example 2 — Argument Rules

Only the first argument matters, and calling with none gives you the function back.

Ramda
console.log(R.identity(1, 2, 3));
// → 1

console.log(R.identity(undefined));
// → undefined

console.log(typeof R.identity());
// → "function"
Try It Yourself

How It Works

  1. Extra arguments. 2 and 3 are never read, so the result is 1.
  2. Explicit undefined. One argument was passed, so identity returns it — undefined.
  3. No argument. Ramda’s curry sees zero arguments and returns R.identity itself.
  4. Lesson. Always pass the value when you want the value.

Example 3 — Keep or Replace with R.ifElse

Replace missing values with a label; keep everything else as-is.

Ramda
const orDefault = R.ifElse(
  R.isNil,
  R.always("n/a"),
  R.identity
);

console.log(orDefault(null));
// → "n/a"

console.log(orDefault("Ada"));
// → "Ada"

console.log(orDefault(0));
// → 0
Try It Yourself

How It Works

  1. Build the branch. R.ifElse takes a test, a “then” function, and an “else” function.
  2. null. R.isNil is true, so R.always("n/a") replaces it.
  3. "Ada". Not nil, so R.identity keeps it unchanged.
  4. 0. Zero is not nil, so it is kept too — identity never changes the value.

Example 4 — Truthy Filter

Use identity as a predicate to keep only truthy items, and see when that is too strict.

Ramda
const values = [0, 1, "", "hi", null];

console.log(R.filter(R.identity, values));
// → [1, "hi"]

console.log(R.reject(R.isNil, values));
// → [0, 1, "", "hi"]
Try It Yourself

How It Works

  1. Predicate = the item. R.filter calls identity on each item, so the item itself decides.
  2. Falsy items drop. 0, "", and null are falsy → result [1, "hi"].
  3. Need zero? R.reject(R.isNil) removes only null / undefined.
  4. Pick on purpose. “Truthy” and “not missing” are different rules.

Example 5 — Count and Sort the Values Themselves

When a helper wants a “key” function and the key is the value, pass identity.

Ramda
const votes = ["a", "b", "a", "c", "a"];

console.log(R.countBy(R.identity, votes));
// → { a: 3, b: 1, c: 1 }

console.log(R.sortBy(R.identity, [3, 1, 2]));
// → [1, 2, 3]
Try It Yourself

How It Works

  1. Key function. R.countBy calls the function on each item to get a group key.
  2. Key = value. Identity returns "a", "b", … so each vote tallies under its own name.
  3. Sort the same way. R.sortBy compares what identity returns — the numbers themselves.
  4. Non-mutating. Both return new results; votes is unchanged.

Browser & Runtime Support

R.identity is a Ramda Function helper since v0.1.0 — one of the original APIs. It runs anywhere Ramda runs: modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install ramda.

✓ Stable · Ramda 0.1.0+

R.identity()

Present in every Ramda release. Uses no browser-specific API, so support depends only on loading Ramda itself.

100% With Ramda 0.1.0+
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
R.identity Ramda 0.1.0+

Bottom line: Safe for production once Ramda is loaded. Use a CDN build such as ramda.min.js in the browser, or install ramda from npm for Node. The labs on this page use [email protected].

Frequently Asked Questions

R.identity(x) returns x unchanged. Its type is a → a. The official docs sample is R.identity(1); //=> 1. Ramda describes it as a good default or placeholder function.
No. R.identity(obj) === obj is true — you get the very same reference back, so mutating the result also changes the original. Use R.clone when you need a copy.
R.identity(x) returns the argument x. R.always(value) returns a function that ignores its argument and always returns value. Use identity to keep the input; use always to replace it.
They behave the same. R.identity is shorter, reads as intent (keep the value), and is one shared function instead of a new arrow on every render or call.
R.filter keeps an item when the predicate result is truthy. Identity returns the item itself, so falsy items — 0, '', null, undefined, NaN, false — are dropped. Use R.reject(R.isNil, list) if 0 and '' must stay.
No. R.identity has been part of Ramda since v0.1.0 and is stable — not deprecated, experimental, or non-standard. Lodash and Underscore offer the same helper as _.identity.

Next: R.invoker()

Learn how to turn a named method into a curried, data-last function.

R.invoker() 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