当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

tap

优质
小牛编辑
138浏览
2023-12-01

Passes each element in the sequence to the specified callback during iteration. This is like Sequence#each, except that it can be inserted anywhere in the middle of a chain of methods to "intercept" the values in the sequence at that point.

Signature

Sequence.tap = function(callback) { /*...*/ }
Sequence.tap = function tap(callback) {
  return new TappedSequence(this, callback);
}
NameType(s)Description
callbackFunction

A function to call on every element in the sequence during iteration. The return value of this function does not matter.

returnsSequence

A sequence comprising the same elements as this one.

Examples

Lazy([1, 2, 3]).tap(fn).each(Lazy.noop); // calls fn 3 times