Ramda.js R.constructN() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Wraps a constructor inside a curried factory whose arity you choose (official Ramda docs). That lets variadic constructors (where fn.length is 0) still wait for n arguments — no new at the call site.

Stable since v0.4.0: R.constructN is a core Ramda helper — not deprecated, experimental, or non-standard. Use it when fn.length is wrong (variadic / rest args). Prefer R.construct when length is already honest.

Syntax

Call R.constructN. Start with this line.

Ramda
R.constructN(n, fn)
CallWhat it does
R.constructN(n, fn)Primary signature.
R.constructN(...)Call the function helper.

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

Library declarations
Ramda
R.constructN(n, fn)

Parameters

ParameterDescription
nRequired. Arity of the returned factory
fnRequired. Constructor to wrap

Return Value

Return ValueDescription
*Curried factory; instance when fully applied

Ramda Examples

Example 1 — Official ThreeLayerSalad

Wrap a variadic Salad for 3 args, skip new, then print the recipe.

Ramda
function Salad() {
  this.ingredients = arguments;
}
Salad.prototype.recipe = function () {
  const instructions = R.map(
    (ingredient) => 'Add a dollop of ' + ingredient,
    this.ingredients
  );
  return R.join('\n', instructions);
};

const ThreeLayerSalad = R.constructN(3, Salad);
const salad = ThreeLayerSalad('Mayonnaise')('Potato Chips')('Ketchup');

console.log(salad.recipe());
Try It Yourself

How It Works

  1. Length lies. Salad only uses arguments, so Salad.length is 0.
  2. Name the arity. constructN(3, Salad) waits for three ingredients.
  3. Curried build. After the third string, you get a real Salad instance (no new).
  4. Prototype stays. recipe() maps each ingredient to a dollop line and joins them.

Example 2 — Curried Calls vs One Call

Pass three ingredients one at a time or all at once — same salad.

Ramda
function Salad() {
  this.ingredients = Array.prototype.slice.call(arguments);
}

const ThreeLayerSalad = R.constructN(3, Salad);

console.log(JSON.stringify(
  ThreeLayerSalad('Mayonnaise')('Potato Chips')('Ketchup').ingredients
));
console.log(JSON.stringify(
  ThreeLayerSalad('Mayonnaise', 'Potato Chips', 'Ketchup').ingredients
));
Try It Yourself

How It Works

  1. Partial apply. After one or two args, the result is still a function.
  2. Full apply. The instance appears only when the third argument arrives.
  3. One-shot style. Passing all three at once also works.
  4. Same args. Both styles feed the same three strings into new Salad.

Example 3 — R.constructN vs R.construct

Plain construct reads Salad.length (0) and ignores extras; constructN keeps them.

Ramda
function Salad() {
  this.ingredients = Array.prototype.slice.call(arguments);
}

const byFnLength = R.construct(Salad);
const threeLayer = R.constructN(3, Salad);

console.log(JSON.stringify(byFnLength('Mayo', 'Chips', 'Ketchup').ingredients));
console.log(JSON.stringify(threeLayer('Mayonnaise')('Potato Chips')('Ketchup').ingredients));
Try It Yourself

How It Works

  1. Construct shorthand. R.construct(Salad) is R.constructN(0, Salad).
  2. Empty bowl. A 0-arity factory calls new Salad() immediately — extras never arrive → [].
  3. ConstructN fix. Naming 3 collects all three ingredients.
  4. Why docs ship both. Use construct when length is honest; use constructN when it is not.

Example 4 — Two Layers vs Three Layers

The same constructor can be wrapped twice — n belongs to the factory.

Ramda
function Salad() {
  this.ingredients = Array.prototype.slice.call(arguments);
}

const twoLayer = R.constructN(2, Salad);
const threeLayer = R.constructN(3, Salad);

console.log(JSON.stringify(twoLayer('Mayo')('Chips').ingredients));
console.log(JSON.stringify(threeLayer('Mayo')('Chips')('Ketchup').ingredients));
Try It Yourself

How It Works

  1. Same constructor. Salad does not change — only the factory arity does.
  2. Two-layer. Instance appears after the second string.
  3. Three-layer. Waits one step longer for ketchup.
  4. Pick n for call sites. Match the number of args you want to collect, not the constructor body.

Example 5 — When fn.length Is Already Honest

A Point with two named parameters does not need constructN — both helpers match.

Ramda
function Point(x, y) {
  this.x = x;
  this.y = y;
}

console.log(JSON.stringify(R.constructN(2, Point)(3)(4)));
console.log(JSON.stringify(R.construct(Point)(3)(4)));
Try It Yourself

How It Works

  1. Honest length. Point.length is 2.
  2. Equivalent wrap. R.construct(Point) is R.constructN(2, Point).
  3. Same point. Both factories build { x: 3, y: 4 }.
  4. Rule of thumb. Prefer construct when length is right; prefer constructN for variadic / rest / defaults that shrink length.

Browser & Runtime Support

R.constructN() is ordinary JavaScript once Ramda is loaded. It needs no special browser API — only a JS runtime that can run Ramda v0.4.0+.

✓ Ramda 0.4.0+ · Any JS runtime

Ramda.js R.constructN()

Works in every modern browser and runtime where you can load Ramda 0.4.0 or later (CDN or npm). Older Ramda builds before 0.4.0 do not include constructN.

100% With Ramda 0.4+
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.constructN() Universal

Bottom line: Safe in any project that includes Ramda 0.4.0 or later. Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Bun, and Deno.

Frequently Asked Questions

R.constructN(n, fn) wraps a constructor in a curried factory with arity n. You call it with n arguments (one call or several) and get back an instance of the same type — without writing new at the call site. The n argument exists so variadic constructors still work.
function Salad() stores arguments as ingredients. ThreeLayerSalad = R.constructN(3, Salad), then ThreeLayerSalad('Mayonnaise')('Potato Chips')('Ketchup').recipe() prints three Add a dollop of ... lines. Added in v0.4.0.
R.construct reads fn.length. A constructor that only uses arguments reports length 0, so construct calls new Fn() with no args. R.constructN(n, fn) lets you name the arity. R.construct(fn) is R.constructN(fn.length, fn).
Not at the call site. constructN uses new for you when all n arguments are supplied. ThreeLayerSalad('Mayonnaise')('Potato Chips')('Ketchup') is the same kind of object as new Salad('Mayonnaise', 'Potato Chips', 'Ketchup').
Yes. After n arguments arrive, you get an instance. ThreeLayerSalad('Mayonnaise')('Potato Chips')('Ketchup') and ThreeLayerSalad('Mayonnaise', 'Potato Chips', 'Ketchup') both work. constructN itself is also curried, so R.constructN(3)(Salad) is valid.
No. R.constructN is a stable Ramda function helper from v0.4.0. It is not deprecated, experimental, or non-standard.

Next: R.converge()

Apply several branch functions to the same args, then combine their results.

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

12 people found this page helpful