liveBook · Manning

Tap combinator

As explained in Functional Programming in JavaScript

A combinator that applies a function to a value for its side effects and then returns the original value unchanged.

The tap combinator lets a function perform a side effect, such as logging, inside a composition without changing the value flowing through it. It bridges useful void functions with functional control flow. section 4.6

Logging during a composition

const debug = R.tap(debugLog);\nconst cleanInput = R.compose(normalize, debug, trim);\n\nconst isValidSsn = R.compose(debug, checkLengthSsn, debug, cleanInput);\nisValidSsn('444-44-4444');\n\n// logs intermediate values, then returns the final result section 4.6

tap :: (a -> *) -> a -> a

Use the signature to see that tap accepts an action and returns the original input after running that action. section 4.6

How Functional Programming in JavaScript covers it

How deep it goes
Defines tap’s behavior and signature, then demonstrates intermediate logging in composed JavaScript functions.
Examples
Uses debug logging to inspect cleaned input, length checks, and the final validation result.
What you can do after
Apply it via R.tap to add diagnostic actions to a composition without altering its returned value.
How it connects
Connects tap with higher-order functions, function composition, combinators, side effects, and void functions.

Also explained in

Compare how 2 books explain tap combinator →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in JavaScript. The section links point to the parts of the book it draws on.