Ramda.js R.rebuild() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.rebuild(convert, obj) builds a new object by turning every key-value pair of obj into zero, one, or many new pairs (official Ramda docs).

Warning — new in v0.31.0: R.rebuild does not exist in Ramda 0.30.x and older (R.rebuild is not a function). This page and its labs use [email protected].

Syntax

Call R.rebuild. Start with this line.

Ramda
R.rebuild(convert, obj)
CallWhat it does
R.rebuild(convert, obj)Primary signature.
R.rebuild(...)Call the list helper.

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

Library declarations
Ramda
R.rebuild(convert, obj)

Parameters

This helper has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*The value returned by R.rebuild().

Ramda Examples

Example 1 — Official Sample

Uppercase every key and square every value in one pass.

Ramda
const result = R.rebuild(
  (k, v) => [[k.toUpperCase(), v * v]],
  { a: 1, b: 2, c: 3 }
);

console.log(result); // {"A":1,"B":4,"C":9}
Try It Yourself

How It Works

  1. Per entry. convert runs three times: ('a', 1), ('b', 2), ('c', 3).
  2. One pair each. It returns [['A', 1]], [['B', 4]], [['C', 9]].
  3. Combine. The pairs become { A: 1, B: 4, C: 9 }.

Example 2 — Drop Empty Values from Query Params

Return [] to remove an entry. Here empty and missing values are dropped and the rest become strings.

Ramda
const params = { q: 'ramda', page: 2, sort: '', tag: null };

const clean = R.rebuild(
  (k, v) => (v == null || v === '' ? [] : [[k, String(v)]]),
  params
);

console.log(clean); // {"q":"ramda","page":"2"}
Try It Yourself

How It Works

  1. Check. v == null catches null and undefined; v === '' catches empty strings.
  2. Drop. sort and tag return [], so they vanish.
  3. Keep + convert. q and page return one pair each, with 2 turned into '2'.

Example 3 — One Entry Becomes Many (Flatten One Level)

Return several pairs to turn a nested object into dotted keys.

Ramda
const box = { size: { w: 2, h: 3 }, pos: { x: 0 } };

const flat = R.rebuild(
  (k, inner) => R.toPairs(inner).map(([k2, v]) => [k + '.' + k2, v]),
  box
);

console.log(flat); // {"size.w":2,"size.h":3,"pos.x":0}
Try It Yourself

How It Works

  1. Inner pairs. R.toPairs({ w: 2, h: 3 }) → [['w', 2], ['h', 3]].
  2. New keys. Each inner key gets the outer key in front: 'size.w', 'size.h'.
  3. Many pairs. size returns two pairs and pos returns one → three keys in total.

Example 4 — Filter and Rename in One Step

Keep only APP_ settings and turn APP_PORT into port.

Ramda
const env = { APP_PORT: '3000', APP_MODE: 'dev', PATH: '/usr/bin' };

const config = R.rebuild(
  (k, v) => (k.startsWith('APP_') ? [[k.slice(4).toLowerCase(), v]] : []),
  env
);

console.log(config); // {"port":"3000","mode":"dev"}
Try It Yourself

How It Works

  1. Filter. PATH doesn’t start with 'APP_', so it returns [] and is dropped.
  2. Rename. k.slice(4) removes 'APP_'; toLowerCase() gives 'port' and 'mode'.
  3. Why rebuild. R.mapKeys can rename but not drop; R.pickBy can drop but not rename. R.rebuild does both.

Example 5 — What R.rebuild Does Inside

It is toPairs, then chain, then fromPairs. Both lines print the same object.

Ramda
const convert = (k, v) => [[k.toUpperCase(), v * v]];
const obj = { a: 1, b: 2, c: 3 };

const manual = R.pipe(
  R.toPairs,
  R.chain(([k, v]) => convert(k, v)),
  R.fromPairs
);

console.log(R.rebuild(convert, obj)); // {"A":1,"B":4,"C":9}
console.log(manual(obj));             // {"A":1,"B":4,"C":9}
Try It Yourself

How It Works

  1. toPairs. { a: 1, … } → [['a', 1], ['b', 2], ['c', 3]].
  2. chain. R.chain runs convert on each pair and flattens the lists one level.
  3. fromPairs. R.fromPairs turns the pairs back into an object.
  4. Takeaway. R.rebuild is this pipeline in one call, with convert getting key and value separately.

Browser & Runtime Support

R.rebuild() is plain JavaScript inside Ramda 0.31.0+. No special browser API is needed.

✓ Ramda 0.31.0+ · Any JS runtime

Ramda.js R.rebuild()

The UMD build (ramda.min.js) runs in Chrome, Firefox, Safari, and Edge, and in Node.js, Deno, and Bun. The only requirement is a Ramda version that includes it.

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

Bottom line: Safe in any project on Ramda 0.31.0 or later (check with npm ls ramda). Not available in 0.30.x. Load ramda.min.js from a CDN in the browser, or npm install ramda@latest for Node, Deno, and Bun. These labs load [email protected].

Frequently Asked Questions

R.rebuild(convert, obj) calls convert(key, value) for every own key of obj. Each call returns a list of [key, value] pairs (zero, one, or many), and all pairs are combined into a new object.
R.rebuild((k, v) => [[k.toUpperCase(), v * v]], {a: 1, b: 2, c: 3}) returns {A: 1, B: 4, C: 9}.
Return an empty list [] for that entry. Nothing is added for it, so the key disappears from the result.
R.map changes only values, R.mapKeys changes only keys, and both keep one output key per input key. R.rebuild can change keys and values together, drop entries, or produce several entries from one.
R.rebuild was added in Ramda v0.31.0. Ramda 0.30.x and older do not have it. Upgrade with npm install ramda@latest, or load [email protected] from a CDN.
No. R.rebuild is a newer addition (v0.31.0) and is not deprecated, experimental, or non-standard. It just needs a recent Ramda version.

Next: R.reduce()

Combine every item of a list into one result, step by step.

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