Ramda.js R.tap() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

A helper that runs a function for its side effect — logging, counting, saving — and then returns the original value. Whatever the function returns is thrown away.

Ramda’s docs write it as (f(a), a) using the comma operator: do f(a), then give back a. Status: stable since Ramda v0.1.0 — not deprecated, experimental, or non-standard.

Syntax

Call R.tap. Start with this line.

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

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

Library declarations
Ramda
R.tap(fn, x)

Parameters

ParameterDescription
fnRequired. Function called with x; its return value is thrown away
xRequired. Any value to pass to fn and then return

Return Value

Return ValueDescription
*The same x (same reference for objects)

Ramda Examples

Example 1 — Official sayX

Log a value and still get it back.

Ramda
const sayX = x => console.log("x is " + x);

const result = R.tap(sayX, 100);
// logs "x is 100"

console.log(result);
// → 100
Try It Yourself

How It Works

  1. Effect. Tap calls sayX(100), which prints x is 100.
  2. Ignore. console.log returns undefined; tap throws that away.
  3. Return. Tap hands back the original 100.

Example 2 — fn’s Return Is Ignored

Even a function that returns something useful can’t change tap’s result.

Ramda
const double = x => x * 2;
console.log(R.tap(double, 10));
// → 10

const user = { name: "Ada" };
console.log(R.tap(R.keys, user) === user);
// → true
Try It Yourself

How It Works

  1. Number. double(10) computes 20, but tap discards it and returns 10.
  2. Object. R.keys builds ["name"] — also discarded.
  3. Same reference. Tap returns the very same user object, so === is true.
  4. Rule. To change data, use a real step such as R.map, not tap.

Example 3 — The console.log Trap

The same pipe with and without tap. Only one gives the right answer.

Ramda
const log = x => console.log("saw " + x);

const broken = R.pipe(R.add(1), log, R.multiply(2));
const fixed = R.pipe(R.add(1), R.tap(log), R.multiply(2));

console.log(broken(10));
// logs "saw 11", then → NaN

console.log(fixed(10));
// logs "saw 11", then → 22
Try It Yourself

How It Works

  1. Same start. Both pipes turn 10 into 11 with R.add(1).
  2. Broken. log returns undefined, so R.multiply(2) gets undefined → NaN.
  3. Fixed. R.tap(log) logs, then passes 11 on → 22.

Example 4 — Audit Each Stage of a Pipe

Record how many items survive each step while the data keeps moving.

Ramda
const sizes = [];
const record = list => sizes.push(list.length);

const bigTimesTen = R.pipe(
  R.tap(record),
  R.filter(n => n > 2),
  R.tap(record),
  R.map(R.multiply(10))
);

console.log(bigTimesTen([1, 2, 3, 4]));
// → [30, 40]

console.log(sizes);
// → [4, 2]
Try It Yourself

How It Works

  1. First tap. Records 4 (the input length) and passes the list on.
  2. Filter. R.filter keeps [3, 4].
  3. Second tap. Records 2. push returns a number, but tap ignores it.
  4. Map. Multiplies by 10 → [30, 40]; sizes holds the audit trail.

Example 5 — Tap Inside a Transducer

Given a transformer, tap runs once per item that reaches it.

Ramda
const seen = [];

const xf = R.compose(
  R.filter(n => n % 2 === 1),
  R.tap(n => seen.push(n)),
  R.map(R.inc)
);

console.log(R.into([], xf, [1, 2, 3, 4]));
// → [2, 4]

console.log(seen);
// → [1, 3]
Try It Yourself

How It Works

  1. Order. In a transducer, R.compose runs left to right per item: filter, tap, map.
  2. Filter. Only odd numbers 1 and 3 pass.
  3. Tap. Records each passing item in seen → [1, 3].
  4. Map. R.inc adds 1, and R.into collects [2, 4].

Browser & Runtime Support

R.tap has been in Ramda since v0.1.0. Ramda’s browser build is plain ES5, so it runs in any modern browser and in Node.js / Bun / Deno with npm install ramda.

✓ Stable · Ramda 0.1.0+

R.tap()

Available in every Ramda release. The examples use ES2015 arrow functions, supported by every evergreen browser.

100% With any Ramda version
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.tap Ramda 0.1.0+

Bottom line: Safe for production in any project that includes Ramda. The labs on this page use [email protected].

Frequently Asked Questions

R.tap(fn, x) calls fn(x), throws away whatever fn returns, and returns x unchanged. The docs sample: R.tap(sayX, 100) //=> 100, and it logs 'x is 100'.
Both return x. R.identity does nothing else; R.tap runs fn(x) first. Think of tap as identity plus a side effect — swap one for the other to switch a debug log on or off.
console.log returns undefined, so the next step receives undefined. R.pipe(R.add(1), console.log, R.multiply(2))(10) logs 11 but returns NaN. Wrapping it as R.tap(console.log) keeps 11 flowing and returns 22.
No. It returns the same reference. If fn mutates an object, the change is visible to every later step. Use R.assoc or R.clone when you need a new object.
R.tap does not wait for anything: an async fn's promise is thrown away and x is returned immediately. To peek at a resolved value, put tap inside R.andThen: R.andThen(R.tap(log)).
No. R.tap has been a stable Ramda function helper since v0.1.0 — not deprecated, experimental, or non-standard.

Next: R.thunkify()

Learn how to wrap a function so it waits until you call the thunk.

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