Skip to main content

tap

tap() function

This method invokes interceptor and returns a value. The interceptor is invoked with one argument.

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

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

Example

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]>