Ramda.js R.pipeWith() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

R.pipeWith(transformer, [f, g, h]) builds a left-to-right pipeline like R.pipe, but a transformer sits between the steps and decides how each result reaches the next function (official Ramda docs).

Stable since v0.26.0: R.pipeWith is not deprecated, experimental, or non-standard. Its right-to-left twin is R.composeWith.

Syntax

Call R.pipeWith. Start with this line.

Ramda
R.pipeWith(transformer, [f, g, h])
CallWhat it does
R.pipeWith(transformer, [f, g, h])Primary signature.
R.pipeWith(...)Call the function helper.

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

Library declarations
Ramda
R.pipeWith(transformer, [f, g, h])

Parameters

ParameterDescription
transformerRequired. Receives (next, res); returns the value for the next step
functionsRequired. Steps in run order; the first gets all the arguments

Return Value

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

Ramda Examples

Example 1 — Official pipeWhileNotNil

A transformer that only continues while the result is not null or undefined. This is the sample from the Ramda docs.

Ramda
const pipeWhileNotNil = R.pipeWith((f, res) =>
  R.isNil(res) ? res : f(res)
);

const f = pipeWhileNotNil([Math.pow, R.negate, R.inc]);

console.log(f(3, 4)); // -80
Try It Yourself

How It Works

  1. Pipe maker. Passing only the transformer returns pipeWhileNotNil, ready for any array of steps.
  2. First step. Math.pow(3, 4) runs directly → 81.
  3. Checked steps. R.isNil is false each time, so R.negate → -81, then R.inc → -80.
  4. Same as pipe. With no nil values, the result matches R.pipe(Math.pow, R.negate, R.inc).

Example 2 — Stop Safely on Missing Data

Read a nested city and uppercase it, without crashing when part of the object is missing.

Ramda
const pipeWhileNotNil = R.pipeWith((f, res) =>
  R.isNil(res) ? res : f(res)
);

const getCity = pipeWhileNotNil([R.prop('address'), R.prop('city'), R.toUpper]);

console.log(getCity({ address: { city: 'paris' } })); // "PARIS"
console.log(getCity({}));                             // undefined
Try It Yourself

How It Works

  1. Full object. R.prop('address') → { city: 'paris' } → 'paris' → R.toUpper → 'PARIS'.
  2. Empty object. R.prop('address') returns undefined.
  3. Skip. The transformer sees nil and returns it, so R.prop('city') and R.toUpper never run.
  4. Why it helps. With plain R.pipe, R.toUpper(undefined) would throw a TypeError.

Example 3 — Pipe Async Steps with R.andThen

Each step waits for the previous Promise, so you can mix async and normal functions.

Ramda
const fetchUser = (id) => Promise.resolve({ id: id, name: 'ada' });

const getUserName = R.pipeWith(R.andThen, [fetchUser, R.prop('name'), R.toUpper]);

getUserName(1).then(console.log); // "ADA"
Try It Yourself

How It Works

  1. First step. fetchUser(1) returns a Promise of { id: 1, name: 'ada' } (a stand-in for a real API call).
  2. Transformer. R.andThen(next, promise) waits, then calls next with the resolved value.
  3. Next steps. R.prop('name') → 'ada', then R.toUpper → 'ADA'.
  4. Result. The pipeline returns a Promise, so read it with .then or await.

Example 4 — Log Every Value Between Steps

A transformer can record values for debugging, then continue as normal.

Ramda
const seen = [];

const pipeLogged = R.pipeWith((f, res) => {
  seen.push(res);
  return f(res);
});

const result = pipeLogged([R.add(1), R.multiply(2), R.negate])(5);

console.log(result); // -12
console.log(seen);   // [6, 12]
Try It Yourself

How It Works

  1. First step. R.add(1) runs directly: 5 + 1 → 6 (not logged).
  2. Before step 2. The transformer logs 6, then R.multiply(2) → 12.
  3. Before step 3. It logs 12, then R.negate → -12.
  4. Proof. seen has two values: the transformer runs once per step after the first.

Example 5 — A Pass-Through Transformer Equals R.pipe

If the transformer just calls the next function, you get a normal pipe.

Ramda
const plainPipe = R.pipeWith((f, res) => f(res));

console.log(plainPipe([R.inc, R.multiply(2)])(4)); // 10
console.log(R.pipe(R.inc, R.multiply(2))(4));      // 10
Try It Yourself

How It Works

  1. Pass-through. (f, res) => f(res) adds no extra rule.
  2. Steps. R.inc(4) → 5, then R.multiply(2) → 10.
  3. Different shape. pipeWith takes an array; R.pipe takes separate arguments.
  4. Takeaway. pipeWith is pipe plus one hook between steps.

Browser & Runtime Support

R.pipeWith() is plain JavaScript inside Ramda 0.26.0+. Async pipelines with R.andThen also need native Promises.

✓ Ramda 0.26.0+ · Any JS runtime

Ramda.js R.pipeWith()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge. Promises are built into every modern browser and into Node.js, Deno, and Bun.

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

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

Frequently Asked Questions

R.pipeWith(transformer, [f, g, h]) builds a left-to-right pipeline like R.pipe, but every step after the first goes through your transformer. The transformer receives (nextFunction, previousResult) and decides what happens: call it, skip it, or change the value.
const pipeWhileNotNil = R.pipeWith((f, res) => R.isNil(res) ? res : f(res)); const f = pipeWhileNotNil([Math.pow, R.negate, R.inc]); f(3, 4) returns -80. If any step returned null or undefined, the remaining steps would be skipped.
Use R.pipeWith(R.andThen, [stepA, stepB]). R.andThen waits for each Promise and passes its value to the next step. The first step must return a Promise, otherwise R.andThen throws a TypeError.
No. The first function runs directly with the original arguments, so it can take several of them. The transformer only wraps the steps after it.
They work the same way in opposite directions. R.pipeWith runs the array left to right; R.composeWith runs it right to left. Reverse the array to switch between them.
No. R.pipeWith has been a stable Ramda function helper since v0.26.0. It is not deprecated, experimental, or non-standard.

Next: R.promap()

Transform what goes into a function and what comes out.

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