Licence
MIT
Version
0.1.0
Deps
0
Vulns
0
Weekly
0
tap
Runs a given function with the supplied object, then returns the object.
Installation
$ npm install @f/tap
Usage
var tap = require('@f/tap')
var log = tap(console.log.bind(console))
var ten = log(10)
// -> returns` you 10 and logs it
Why?
Let's say you have a some kind of a reducing function in es2015 where you want to log a given state. Instead of refactoring it to a larger function you can just wrap it in a tap(console)
const reducer = (state, action) => [...state, id: action.payload]
// instead of
const reducer = (state, action) => {
console.log(state)
return [...state, id: action.payload]
}
// you can just wrap it
const reducer = (state, action) => [...log(state), id: action.payload]
This simplifies quick debugging a lot.
API
tap(fn)
fn- Side effect function
Returns: A function which can be called with an argument to execute fn and return the object
License
MIT