Ramda.js R.compose() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Performs right-to-left function composition (official Ramda docs). The last argument may have any arity; the remaining arguments must be unary. You get one new function that runs the rightmost step first.

Stable since v0.1.0: R.compose is a core Ramda helper — not deprecated, experimental, or non-standard. The result is not auto-curried. Prefer R.pipe when left-to-right reads clearer.

Syntax

Call R.compose. Start with this line.

Ramda
R.compose(f, g, h)
CallWhat it does
R.compose(f, g, h)Primary signature.
R.compose(...)Call the function helper.

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

Library declarations
Ramda
R.compose(f, g, h)

Parameters

ParameterDescription
…functionsRequired. Rightmost may be multi-arg; others must be unary

Return Value

Return ValueDescription
*One function with the arity of the rightmost step

Ramda Examples

Example 1 — Official Math Pipeline

Multiply, add, then take absolute value — right to left.

Ramda
const result = R.compose(Math.abs, R.add(1), R.multiply(2))(-4);

console.log(result); // 7
Try It Yourself

How It Works

  1. Start on the right. R.multiply(2)(-4) → -8.
  2. Next unary step. R.add(1)(-8) → -7.
  3. Finish on the left. Math.abs(-7) → 7.
  4. One call. The composed function takes -4 and returns the final number.

Example 2 — Official yellGreeting

The rightmost function takes two args; R.toUpper is unary on the left.

Ramda
const classyGreeting = (firstName, lastName) =>
  "The name's " + lastName + ", " + firstName + " " + lastName;

const yellGreeting = R.compose(R.toUpper, classyGreeting);

console.log(yellGreeting('James', 'Bond'));
Try It Yourself

How It Works

  1. Rightmost first. classyGreeting('James', 'Bond') builds the Bond line.
  2. Unary next. R.toUpper uppercases that whole string.
  3. Pass both names at once. The composed function is not curried.
  4. Arity rule. Only the last listed function may take multiple arguments.

Example 3 — R.compose vs R.pipe

Same three steps, opposite list order — both yield 7.

Ramda
const composed = R.compose(Math.abs, R.add(1), R.multiply(2))(-4);
const piped = R.pipe(R.multiply(2), R.add(1), Math.abs)(-4);

console.log(composed); // 7
console.log(piped);    // 7
Try It Yourself

How It Works

  1. Compose reads like math. Last step listed first: abs ∘ add ∘ multiply.
  2. Pipe reads like a recipe. First step listed first: multiply, then add, then abs.
  3. Same path. Both run -4 → -8 → -7 → 7.
  4. Pick for clarity. Prefer R.pipe when “do this, then that” is easier to read.

Example 4 — Get a Field, Then Transform

Read name, then uppercase it — a common object pipeline.

Ramda
const shoutName = R.compose(R.toUpper, R.prop('name'));

console.log(shoutName({ name: 'emma' })); // "EMMA"
Try It Yourself

How It Works

  1. Rightmost first. R.prop('name') reads 'emma' from the object.
  2. Transform next. R.toUpper returns 'EMMA'.
  3. Both unary. Each step takes one value and returns one value.
  4. Reusable helper. Name it once; call it on any object with a name field.

Example 5 — String Cleanup Pipeline

Trim, lower-case, then replace spaces to build a simple slug.

Ramda
const slug = R.compose(
  R.replace(/ /g, '-'),
  R.toLower,
  R.trim
);

console.log(slug('  Hello World  ')); // "hello-world"
Try It Yourself

How It Works

  1. Trim first (right). R.trim removes leading/trailing spaces.
  2. Lowercase. R.toLower → 'hello world'.
  3. Replace last (left). Spaces become hyphens → 'hello-world'.
  4. Read bottom-up in the list. Rightmost runs first; leftmost finishes.

Browser & Runtime Support

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

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.compose()

Works in every modern browser and runtime where you can load Ramda (CDN or npm). Internet Explorer needs a build that targets that environment; there is no native IE API to polyfill.

100% With Ramda loaded
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.compose() Universal

Bottom line: Safe in any project that includes Ramda 0.1.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.compose(f, g, h) returns a new function that runs right to left: h first, then g, then f. The last argument may take several values; every function before it must be unary. The result is not automatically curried.
R.compose(R.toUpper, classyGreeting)('James', 'Bond') yields "THE NAME'S BOND, JAMES BOND". The math sample is R.compose(Math.abs, R.add(1), R.multiply(2))(-4) which yields 7. Added in v0.1.0. See also R.pipe.
They chain the same way, but in opposite directions. compose is right-to-left (last function runs first). pipe is left-to-right (first function runs first). R.pipe(multiply(2), add(1), Math.abs)(-4) is the same 7 as the compose sample with the list reversed.
No. The docs note that the result of compose is not automatically curried. Call it with every argument the rightmost function needs, in one go: yellGreeting('James', 'Bond'), not yellGreeting('James')('Bond').
Only the last (rightmost) function. The remaining functions must be unary: each receives the previous result as a single value.
No. R.compose is a stable Ramda function helper from v0.1.0. It is not deprecated, experimental, or non-standard.

Next: R.composeWith()

Compose functions with a custom combiner instead of plain nesting.

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

14 people found this page helpful