Ramda.js R.of() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Given a constructor and a value, returns a new instance of that constructor containing the value — the applicative “pure” / of helper. Part of Ramda Function since v0.3.0 (stable — not deprecated).

Warning: Since Ramda v0.29.0, R.of is binary: R.of(Ctor, val). Old unary R.of(42) no longer returns [42] — it returns a function waiting for a value. Use R.of(Array, 42).

Syntax

Call R.of. Start with this line.

Ramda
R.of(Ctor, val) or R.of(Ctor)(val)
CallWhat it does
R.of(Ctor, val) or R.of(Ctor)(val)Primary signature.
R.of(...)Call the function helper.

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

Library declarations
Ramda
R.of(Ctor, val) or R.of(Ctor)(val)

Parameters

ParameterDescription
CtorRequired. Constructor / type with an of method (preferred)
valRequired. Any value to wrap

Return Value

Return ValueDescription
*Instance of Ctor wrapping val (or [val])

Ramda Examples

Example 1 — Official: Wrap with Array

Put a single value into an array using the constructor form.

Ramda
R.of(Array, 42);
// → [42]
Try It Yourself

How It Works

  1. Constructor. First argument is Array.
  2. Dispatch. Ramda finds Array.of and calls it with 42.
  3. Result. One-element array [42].
  4. Curry. Same as R.of(Array)(42).

Example 2 — Official: Nested Array

Wrapping an array wraps it as one element — it does not flatten.

Ramda
R.of(Array, [42]);
// → [[42]]
Try It Yourself

How It Works

  1. Value is an array. [42] is treated as one unit.
  2. Array.of. Puts that unit inside a new array.
  3. Shape. Result is [[42]], not [42].
  4. Rule. of wraps once; it does not concatenate.

Example 3 — Official: Custom Maybe

When a type defines of, Ramda uses it — matching the docs’ Maybe sample.

Ramda
function Maybe(x) {
  this.value = x;
}
Maybe.of = function (x) {
  return new Maybe(x);
};

R.of(Maybe, 42);
// → Maybe { value: 42 }  // docs: Maybe.Just(42)
Try It Yourself

How It Works

  1. Define of. Maybe.of returns new Maybe(x).
  2. Dispatch. R.of(Maybe, 42) calls that method.
  3. Instance. You get a Maybe holding 42.
  4. Fantasy-land. If fantasy-land/of exists, that wins first.

Example 4 — Array Fallback

Constructors without of wrap the value in a plain array.

Ramda
function Plain() {}

R.of(Plain, 7);    // → [7]
R.of(Object, 42);  // → [42]
Try It Yourself

How It Works

  1. No of method. Plain and Object lack of.
  2. Fallback. Docs: wrap the value in an array.
  3. Results. [7] and [42].
  4. Tip. Prefer types that implement of when you need a real instance.

Example 5 — R.of vs Array.of

Binary curry, one-value wrap, and multi-arg ES6 Array.of are different.

Ramda
typeof R.of(42);           // → "function"  (waits for a value)

R.of(Array)(42);           // → [42]
R.of(Array, 10);           // → [10]

Array.of(10, 20);          // → [10, 20]   (many args OK)
Try It Yourself

How It Works

  1. Unary call. R.of(42) only fills the constructor slot → a function.
  2. Complete call. R.of(Array, 10) wraps one value.
  3. ES6 Array.of. Accepts many arguments; see the Array.of tutorial.
  4. Docs note. Ramda’s of is not the same as ES6 of.

Browser & Runtime Support

R.of is a Ramda Function helper since v0.3.0. The current binary signature (Ctor, then val) applies from v0.29.0. It runs anywhere modern Ramda runs — browsers (CDN or bundle) and Node.js / Bun / Deno.

✓ Stable · Binary since 0.29.0

R.of()

Available in full Ramda builds. Prefer Ramda 0.29+ so R.of(Array, val) matches current docs. Works in evergreen browsers and current Node LTS when Ramda is loaded.

100% With Ramda 0.29+
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.of Ramda 0.29.0+ API

Bottom line: Safe for production on Ramda 0.29+. On older Ramda, unary R.of(x) meant [x] — migrate to R.of(Array, x). Official reference: ramdajs.com/docs/#of.

Frequently Asked Questions

R.of(Ctor, val) returns a new instance of Ctor that contains val. It tries Ctor['fantasy-land/of'] first, then Ctor.of, and if neither exists it wraps val in an array: [val]. Added in v0.3.0. Since v0.29.0 it is binary: constructor first, value second.
R.of(Array, 42); //=> [42]. R.of(Array, [42]); //=> [[42]]. R.of(Maybe, 42); //=> Maybe.Just(42) when Maybe implements of.
Array.of can take many arguments: Array.of(10, 20) is [10, 20]. R.of always wraps one value, and the constructor is an argument: R.of(Array, 10) is [10]. They are different functions. See MDN Array.of.
Before Ramda 0.29.0, R.of(x) always returned [x]. Now R.of is curried with two slots, so R.of(42) is a function waiting for a value. Write R.of(Array, 42) to wrap 42 in an array.
Yes. R.of(Array, 42) and R.of(Array)(42) are the same. R.of(Array) is a reusable wrapper you can pass to map.
No. R.of is a stable Ramda Function helper from v0.3.0. The binary constructor signature is the current API from v0.29.0. It is not deprecated, experimental, or non-standard.

Next: R.on()

Apply a binary after transforming both arguments with the same unary function.

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

11 people found this page helpful