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)
Call
What 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
Parameter
Description
fn
Required. Function called with x; its return value is thrown away
x
Required. Any value to pass to fn and then return
Return Value
Return Value
Description
*
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
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 ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
R.tapRamda 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.