Ramda.js R.empty() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Returns the empty value of its argument’s type — [], '', {}, a zero-length typed array, and more. Part of Ramda Function since v0.3.0 (stable — not deprecated, experimental, or non-standard).

Note: Dispatches to .empty / Fantasy Land Monoid when present. Does not mutate the input. Unsupported types return undefined.

Syntax

Call R.empty. Start with this line.

Ramda
R.empty(x)
CallWhat it does
R.empty(x)Primary signature.
R.empty(...)Call the function helper.

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

Library declarations
Ramda
R.empty(x)

Parameters

ParameterDescription
xRequired. Value whose type determines the blank

Return Value

Return ValueDescription
*New empty value, or undefined if unsupported

Ramda Examples

Example 1 — Official Array, String, and Object

The everyday sample from the Ramda docs.

Ramda
console.log(R.empty([1, 2, 3]));
// → []

console.log(R.empty('unicorns'));
// → ''

console.log(R.empty({ x: 1, y: 2 }));
// → {}
Try It Yourself

How It Works

  1. Array. Type is Array → return a new [].
  2. String. Type is String → return ''.
  3. Object. Plain object → return a new {}.
  4. Docs note. With a Fantasy Land Maybe, R.empty(Just(42)) becomes Nothing().

Example 2 — Official Uint8Array

Typed arrays keep their constructor; only length drops to zero.

Ramda
const bytes = Uint8Array.from('123');
const blank = R.empty(bytes);

console.log(blank.constructor.name + ' []');
console.log('length: ' + blank.length);
console.log('source length: ' + bytes.length);
Try It Yourself

How It Works

  1. Build. Uint8Array.from('123') makes a three-byte view.
  2. Empty. R.empty returns another Uint8Array with length 0.
  3. Source. bytes.length is still 3.
  4. Rule. Same constructor family — not converted to a plain array.

Example 3 — Custom Type with empty

Ramda dispatches to constructor.empty when present.

Ramda
function Box(value) {
  this.value = value;
}
Box.empty = function () {
  return new Box(null);
};

const blank = R.empty(new Box(42));
console.log(JSON.stringify(blank));
console.log(blank.constructor.name);
Try It Yourself

How It Works

  1. Define. Box is a custom constructor.
  2. Hook. Box.empty returns new Box(null).
  3. Dispatch. R.empty(new Box(42)) calls that static method → {"value":null}.
  4. Same idea. Fantasy Land types use fantasy-land/empty the same way.

Example 4 — R.empty vs R.isEmpty

One builds the blank; the other asks if a value already is that blank.

Ramda
console.log(R.isEmpty(R.empty([1, 2, 3]))); // → true
console.log(R.isEmpty([1, 2, 3]));          // → false
console.log(R.isEmpty(''));                 // → true
Try It Yourself

How It Works

  1. Build then test. R.empty([1, 2, 3]) is [], which is empty → true.
  2. Filled list. [1, 2, 3] is not blank → false.
  3. Empty string. '' already is the blank → true.
  4. Rule. Use empty to create; use isEmpty to check.

Example 5 — No Mutation, and Numbers Stay Unsupported

The source list is unchanged. Types without a blank return undefined.

Ramda
const nums = [1, 2, 3];
const blank = R.empty(nums);

console.log(blank);          // → []
console.log(nums);           // → [1, 2, 3]
console.log(blank === nums); // → false
console.log(R.empty(42));    // → undefined
Try It Yourself

How It Works

  1. New array. blank is a fresh [].
  2. Source intact. nums still holds 1, 2, 3.
  3. Different refs. blank === nums is false.
  4. Numbers. No empty for a number → undefined (no throw).

Browser & Runtime Support

R.empty is a Ramda Function helper since v0.3.0. It runs anywhere Ramda runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install ramda.

✓ Stable · Ramda 0.3.0+

R.empty()

Available in long-standing Ramda builds. Array, String, Object, and TypedArray empties work in evergreen browsers and current Node LTS when Ramda is installed.

100% With Ramda 0.3.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.empty Ramda 0.3.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. Check your Ramda version if you need Map/Set empty values.

Frequently Asked Questions

R.empty(x) returns a new empty value of the same type as x. Arrays become [], strings become '', objects become {}, and typed arrays become a zero-length typed array. The original value is not mutated.
R.empty([1, 2, 3]); //=> []. R.empty('unicorns'); //=> ''. R.empty({x: 1, y: 2}); //=> {}. R.empty(Uint8Array.from('123')); //=> Uint8Array []. The docs also show R.empty(Just(42)) as Nothing() when a Fantasy Land Maybe type is loaded. Added in v0.3.0.
R.empty(x) builds a blank container of x's type. R.isEmpty(x) returns true or false: is this value already that blank? Pair them: R.isEmpty(R.empty([1, 2, 3])) is true.
No. R.empty([1, 2, 3]) returns a new []. The source array still holds 1, 2, 3. The same is true for objects, strings, and typed arrays.
Unsupported types return undefined. R.empty(42) is undefined. Map and Set empty values arrived in later Ramda releases; the CDN labs on this site use 0.30.1, so R.empty(new Set([1, 2])) is also undefined there.
No. R.empty is a stable Ramda function helper from v0.3.0. It is not deprecated, experimental, or non-standard.

Next: R.F()

Learn the constant function that always returns false.

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

7 people found this page helpful