Function: tap()
Call Signature
tap<
R
,FnReturn
>(fn
): (result
) =>Result
<UnwrapOk
<R
>,UnwrapErr
<R
>>
Defined in: fp.ts:170
Takes a side-effect function and returns a function that accepts a Result. The returned function passes the Result through the side-effect function and returns the original Result unchanged.
Useful for debugging, logging, or performing side effects without modifying the Result.
Type Parameters
R
R
extends Result
The input Result type
FnReturn
FnReturn
The return type of the side-effect function (ignored)
Parameters
fn
(result
) => NonPromise
<FnReturn
>
Side-effect function to execute with the Result
Returns
A function that takes a Result, executes the side-effect function, and returns the original Result
Parameters
result
R
Returns
Result
<UnwrapOk
<R
>, UnwrapErr
<R
>>
Example
const result = pipe(
ok("hello"),
tap((result) => {
console.log("Result:", result); // Logs the result (side-effect)
return "something"; // Return value is ignored
}),
mapOk((data) => data.toUpperCase()), // Original result is passed through
); // { success: true, data: "HELLO" }
Call Signature
tap<
R
,FnReturn
>(fn
): (result
) =>Promise
<Result
<UnwrapOk
<R
>,UnwrapErr
<R
>>>
Defined in: fp.ts:173
Takes a side-effect function and returns a function that accepts a Result. The returned function passes the Result through the side-effect function and returns the original Result unchanged.
Useful for debugging, logging, or performing side effects without modifying the Result.
Type Parameters
R
R
extends OrPromise
<Result
>
The input Result type
FnReturn
FnReturn
The return type of the side-effect function (ignored)
Parameters
fn
(result
) => OrPromise
<FnReturn
>
Side-effect function to execute with the Result
Returns
A function that takes a Result, executes the side-effect function, and returns the original Result
Parameters
result
R
Returns
Promise
<Result
<UnwrapOk
<R
>, UnwrapErr
<R
>>>
Example
const result = pipe(
ok("hello"),
tap((result) => {
console.log("Result:", result); // Logs the result (side-effect)
return "something"; // Return value is ignored
}),
mapOk((data) => data.toUpperCase()), // Original result is passed through
); // { success: true, data: "HELLO" }