Skip to content

tap() function

このメソッドはインターセプターを呼び出し、値を返します。インターセプターは 1 つの引数で呼び出されます。

Signature:

typescript
declare function tap<T, U>(
  f: (arg: Awaited<T>) => U,
  v: T,
): U extends Promise<any> ? Promise<Awaited<T>> : T;

Example

ts
tap(console.log, [1, 2, 3, 4, 5]);
// log [1, 2, 3, 4, 5]
// return [1, 2, 3, 4, 5]

tap(async (a) => console.log(a), [1, 2, 3, 4, 5]);
// log [1, 2, 3, 4, 5]
// return Promise<[1, 2, 3, 4, 5]>

Open Source Code

Released under the Apache-2.0 License.