Tap your functions into method chains for near-seamless interoperability.
Functions give us flexibility about granularity and locality, but they can be awkward to compose with an value's methods.
tap makes using functions & methods together idiomatic, natural, and very easy to read. See here for a fuller discussion.
require'tap-chain'mixinObjectprototypevar return a + breturn a / bvar people =name: 'bob' age: 55name: 'susan' age: 44name: 'charles' age: 20name: 'bex' age: 30var averageAge = peoplemap return pagereduceaddtapdivide peoplelengthtapMathroundaverageAge//= 37
This is equivalent to:
var averageAge = Mathroundpeoplemap return page reduceadd / peoplelength
tap.mixin (object, [objects]) -> object
.tap method into any number of objects. If the environment supports es5, then the property will be set to non-enumerable.
var tap = require'tap-chain'// mix in to base backbone prototypestapmixinBackboneModelprototypeBackboneCollectionprototypeBackboneRouterprototypeBackboneViewprototype// mix in to a newly created objectvar player = tapmixin name: 'scott pilgrim' health: 100// mix in to a 'blank' object (one with no [[Prototype]])var map = tapmixinObjectcreatenull// mix in to everything inheriting from Object.prototype// making .tap work on all non-null/undefined values,// including primitivestapmixinObjectprototype
.tap (fn, [secondary-args]) -> anyValue
.tap method calls a function, using the context of the method as the first argument:
var return v + 1num = 5numtapinc//= 6
.tap also takes optional secondary arguments:
var return a / bnum = 10numtapdivide 2//= 5
npm install tap-chain or download. Creates a CommonJS module if available, otherwise exports a global named