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); }
Name | Type(s) | Description |
---|---|---|
callback | Function | A function to call on every element in the sequence during iteration. The return value of this function does not matter. |
returns | Sequence | A sequence comprising the same elements as this one. |
Examples
Lazy([1, 2, 3]).tap(fn).each(Lazy.noop); // calls fn 3 times