Skip to content

tap() function

이 메서드는 인터셉터를 호출하고 값을 반환합니다. 인터셉터는 하나의 인자로 호출됩니다.

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.