The tap
function from lodash provides a way to perform an operation on a value and return that value without breaking the method chain.
Here's an example using tap
:
index.tsx329 chars10 lines
In this example, we start with the value 5
, perform a console.log
, double the value with map
, perform another console.log
, filter out any values less than or equal to 5 with filter
, and perform a final console.log
before returning the new value.
The output of this code will be:
index.tsx91 chars5 lines
As you can see, the tap
function allows us to "tap into" the value at any point in the chain, perform an operation on it, and continue the chain without breaking it.
gistlibby LogSnag